@unsigned int _ActivateHandler(FPFI handler) This example activates an event handler when the library is loaded. The event handler just prints a message and lets FoxPro process the message as it would normally. The event handler is deactivated when the library is unloaded. Some more functional examples of event handling can be found in the EXAMPLES directory as EVENT.C and SWATCH.C.#include static int HandlerID; // // This is the routine that is registered as an event handler. // FAR EventHandler(WHandle theWindow, EventRec FAR *ev) { _PutStr("\nEventHandler() called."); return NO; // event still needs to be handled by FoxPro } FAR Activate() { HandlerID = _ActivateHandler(EventHandler); return 0; } // // When the library is unloaded we must deactivate the event handler // in a CALLONUNLOAD function. // FAR DeActivate() { _DeActivateHandler(HandlerID); return 0; } FoxInfo myFoxInfo[] = { {"ACTIVATE", Activate, CALLONLOAD, ""}, {"DEACTIVATE", DeActivate, CALLONUNLOAD, ""} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; >SET LIBRARY TO example WAIT TO dummy TIME 5 SET LIBRARY TO Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00255. example.c link.exe @d:\temp\nmb00255. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDCunsigned int _ActivateIdle(FPFI handler) This example activates an idle event handler when the library is loaded. The idle event handler just prints a message. The idle event handler is deactivated when the library is unloaded. #include static unsigned IdlerID; // // This is the routine that is registered as an idle event handler. // void FAR IdleHandler(WHandle wh, EventRec *ev) { _PutStr("\nIdleHandler() called."); } void FAR Activate(ParamBlk FAR *parm) { IdlerID = _ActivateIdle((FPFI) IdleHandler); } // // When the library is unloaded we must deactivate the idle event handler // in a CALLONUNLOAD function. // void FAR DeActivate(ParamBlk FAR *parm) { _DeActivateIdle(IdlerID); } FoxInfo myFoxInfo[] = { {"ACTIVATE", (FPFI) Activate, CALLONLOAD, ""}, {"DEACTIVATE", (FPFI) DeActivate, CALLONUNLOAD, ""} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; >SET LIBRARY TO example WAIT TO dummy TIME 5 SET LIBRARY TO Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00285. example.c link.exe @d:\temp\nmb00285. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDunsigned int _ActivateIdle(FPFI handler) This example builds a popup style "non-modal" menu with three items. _ActivateMenu() displays the menu. This menu is non-modal in that interaction is not forced as with _MenuInteract(). Rather when the user makes a selection the _OnSelection() routine is called, the item selected is printed out to the screen, and the menu disposed of.o#include static MENUID menuId; static long nDidSelect=0; void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); _Execute("clear events"); nDidSelect = itemId; return 0; } void FAR DidSelect(ParamBlk FAR *parm) { Value val; val.ev_long = nDidSelect; val.ev_type = 'I'; _RetVal(&val); } void FAR deactivateMenu(ParamBlk FAR *parm) { _DeActivateMenu(menuId); _DisposeMenu(menuId); } void FAR activateMenu(ParamBlk FAR *parm) { ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _OnSelection(menuId, -1, onSelection); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) activateMenu, CALLONLOAD, ""}, {"DIDSELECT", (FPFI) DidSelect, 0, ""}, {"ONUNLOAD", (FPFI) deactivateMenu, CALLONUNLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; gSET LIBRARY TO example WAIT WINDOW "Make selection from menu." NOWAIT READ EVENTS SET LIBRARY TO Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00271. example.c link.exe @d:\temp\nmb00271. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _ALen(NTI nti, int mode) This example provides an API routine for each of the three possible mode values.S#include void FAR alenElem(ParamBlk FAR *parm) { _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_ELEMENTS), 10); } void FAR alenSub1(ParamBlk FAR *parm) { _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_SUBSCRIPT1), 10); } void FAR alenSub2(ParamBlk FAR *parm) { _RetInt(_ALen(parm->p[0].loc.l_NTI, AL_SUBSCRIPT2), 10); } FoxInfo myFoxInfo[] = { {"ALENELEM", (FPFI) alenElem, 1, "R"}, {"ALENSUB1", (FPFI) alenSub1, 1, "R"}, {"ALENSUB2", (FPFI) alenSub2, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DIMENSION a[10, 11] ? ALENELEM(@a) && returns 110 ? ALENSUB1(@a) && returns 10 ? ALENSUB2(@a) && returns 11 DIMENSION b[3] ? ALENELEM(@b) && returns 3 ? ALENSUB1(@b) && returns 3 ? ALENSUB2(@b) && returns 0; no second subscript c = .F. ? ALENELEM(@c) && returns -1 because variable "c" is not an array ? ALENSUB1(@c) && returns -1 because variable "c" is not an array ? ALENSUB2(@c) && returns -1 because variable "c" is not an array Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00266. example.c link.exe @d:\temp\nmb00266. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED!void FAR * _Alloca(unsigned int size) This example duplicates the functionality of the FoxPro function REPLICATE(). The temporary memory used to duplicate the character comes from _Alloca(). #include void FAR allocaEx(ParamBlk FAR *parm) { char FAR *rep; char c = *(char *) _HandToPtr(parm->p[0].val.ev_handle); rep = _Alloca((int) parm->p[1].val.ev_long + 1); _MemFill(rep, c, (int) parm->p[1].val.ev_long); rep[parm->p[1].val.ev_long] = '\0'; // null terminate _RetChar(rep); } FoxInfo myFoxInfo[] = { {"XREPLICATE", (FPFI) allocaEx, 2, "C,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; CSET LIBRARY TO example x = xREPLICATE("x", 120) ? x ? LEN(x) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00108. example.c link.exe @d:\temp\nmb00108. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDMHANDLE _AllocHand(unsigned int hsize) In this example a character is replicated in memory supplied by _AllocHand(). The API function replToMH() returns the memory handle to FoxPro. From FoxPro the memory handle is passed to API functions which expect a memory handle argument (passed as an integer, "I").:#include // // Replicate char argument to memory allocated with _AllocHand(). // Return the memory handle to FoxPro. // void FAR replToMH(ParamBlk FAR *parm) { char FAR *rep; char c = *(char *) _HandToPtr(parm->p[0].val.ev_handle); MHANDLE mh; if ((mh = _AllocHand((int) parm->p[1].val.ev_long + 1)) == 0) { _Error(182); // "Insufficient memory" } _HLock(mh); rep = _HandToPtr(mh); _MemFill(rep, c, (int) parm->p[1].val.ev_long); rep[parm->p[1].val.ev_long] = '\0'; // null terminate _HUnLock(mh); _RetInt(mh, 10); } // // Returns characters in memory handle. Argument in call from FoxPro // must be a valid FoxPro memory handle. // void FAR MHToFoxString(ParamBlk FAR *parm) { char FAR *string; MHANDLE mh = parm->p[0].val.ev_long; _HLock(mh); string = _HandToPtr(mh); _RetChar(string); _HUnLock(mh); } // // Frees memory handle. Argument in call from FoxPro must be a valid // FoxPro memory handle. // void FAR freeMH(ParamBlk FAR *parm) { _FreeHand((MHANDLE) parm->p[0].val.ev_long); } FoxInfo myFoxInfo[] = { {"REPLTOMH", (FPFI) replToMH, 2, "C,I"}, {"MHTOFOX", (FPFI) MHToFoxString, 1, "I"}, {"FREEMH", (FPFI) freeMH, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; qSET LIBRARY TO example mh = REPLTOMH("x", 120) ? MHTOFOX(mh) ? LEN(MHTOFOX(mh)) ? MHTOFOX(mh) = FREEMH(mh) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00189. example.c link.exe @d:\temp\nmb00189. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _AllocMemo(Locator FAR *fld, long size) This example creates new memo field contents. #include void FAR newMemo(ParamBlk FAR *parm) { Locator FAR *memoFldLoc; FCHAN fchMemo; int memoLen; long loc; if ((fchMemo = _MemoChan(-1)) == -1) { _UserError("_MemoChan() failed"); } memoFldLoc = &parm->p[0].loc; memoLen = parm->p[1].val.ev_length; if ((loc = _AllocMemo(memoFldLoc, memoLen)) == -1) { _UserError("_AllocMemo() failed"); } _FSeek(fchMemo, loc, FS_FROMBOF); _HLock(parm->p[1].val.ev_handle); _FWrite(fchMemo, _HandToPtr(parm->p[1].val.ev_handle), memoLen); _HUnLock(parm->p[1].val.ev_handle); } FoxInfo myFoxInfo[] = { {"NEWMEMO", (FPFI) newMemo, 2, "R,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example CREATE TABLE wMemo (memoField M) APPEND BLANK = NewMemo(@MemoField, "Hello, World.") APPEND BLANK = NewMemo(@MemoField, "Is this or is this ain't fun?") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00138. example.c link.exe @d:\temp\nmb00138. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _BreakPoint(void) This example includes the macro _BreakPoint() which places an INT 3 that debuggers recognize as a break point. t#include void FAR Example(ParamBlk FAR *parm) { int RetValue; _BreakPoint(); // debugger breaks execution here _HLock(parm->p[0].val.ev_handle); _HLock(parm->p[1].val.ev_handle); RetValue = _StrCmp(_HandToPtr(parm->p[0].val.ev_handle), _HandToPtr(parm->p[1].val.ev_handle)); _RetInt(RetValue, 10); // does return control here _HUnLock(parm->p[0].val.ev_handle); _HUnLock(parm->p[1].val.ev_handle); } FoxInfo myFoxInfo[] = { {"STRCMP", (FPFI) Example, 2, "C,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00259. example.c link.exe @d:\temp\nmb00259. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDFint _CountItems(MENUID menuid) This example creates a menu with three items and calls _CountItems() to show that it correctly states the number of items on the menu. It then disposes of items and again calls _CountItems().#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR CountItemsEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _PutStr("\n_CountItems() ="); putLong(_CountItems(menuId)); _Execute("WAIT"); _DisposeItem(menuId, _GetItemId(menuId, 1)); _PutStr("\n_CountItems() ="); putLong(_CountItems(menuId)); _Execute("WAIT"); _DisposeItem(menuId, _GetItemId(menuId, 0)); _PutStr("\n_CountItems() ="); putLong(_CountItems(menuId)); _Execute("WAIT"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) CountItemsEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00298. example.c link.exe @d:\temp\nmb00298. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDbint _DBAppend(int workarea, int carryflag) This example calls _DBAppend() to append a record to the DBF in the current work area. The API library function takes a carry flag as a parameter (passed on to _DBAppend()) and the FoxPro example demonstrates it uses. U#include void FAR Example(ParamBlk FAR *parm) { int RetCode; if ((RetCode = _DBAppend(-1, (int) parm->p[0].val.ev_long)) < 0) { _Error(-RetCode); } } FoxInfo myFoxInfo[] = { {"DBAPPEND", (FPFI) Example, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest SET CARRY ON = DBAPPEND(-1) && SET CARRY is ON, so carry SET CARRY OFF = DBAPPEND(1) && carry regardless of SET CARRY = DBAPPEND(-1) && SET CARRY is OFF, so no carry PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00149. example.c link.exe @d:\temp\nmb00149. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _DBLock(int workarea, int what) This example provides two API functions callable from FoxPro, XRLOCK() which locks the current record of the current work area and XFLOCK() which locks the DBF of the current work area. XRLOCK() calls _DBLock(-1, DBL_RECORD) and XFLOCK() calls _DBLock(-1, DBL_FILE). #include void FAR xLockRecord(ParamBlk FAR *parm) { _DBLock(-1, DBL_RECORD); } void FAR xLockFile(ParamBlk FAR *parm) { _DBLock(-1, DBL_FILE); } FoxInfo myFoxInfo[] = { {"XRLOCK", (FPFI) xLockRecord, 0, ""}, {"XFLOCK", (FPFI) xLockFile, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest USE Test SHARED GO 2 = XRLOCK() LIST STAT && shows that record #2 is locked = XFLOCK() LIST STAT && shows that whole DBF is locked PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00193. example.c link.exe @d:\temp\nmb00193. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _DBRead(int workarea, long record) This example provides similar functionality as the FoxPro command GO. XGO(n) moves the current record pointer to n in the current work area.#include void FAR Example(ParamBlk FAR *parm) { _DBRead(-1, parm->p[0].val.ev_long); } FoxInfo myFoxInfo[] = { {"XGO", (FPFI) Example, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; lSET LIBRARY TO example DO CreateTest USE Test SHARED GO BOTTOM ? RECNO() = XGO(2) ? RECNO() PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00178. example.c link.exe @d:\temp\nmb00178. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _DBRecCount(int workarea) This example calls _DBRecCount() for the DBF in the current work area.  #include void FAR Example(ParamBlk FAR *parm) { _RetInt(_DBRecCount(-1), 10); } FoxInfo myFoxInfo[] = { {"DBRECCOUNT", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest ? DBRECCOUNT() && call API routine ? RECCOUNT() && call built-in FoxPro function PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00247. example.c link.exe @d:\temp\nmb00247. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _DBRecNo(int workarea) This example provides similar functionality as the FoxPro function RECNO(). #include void FAR Example(ParamBlk FAR *parm) { _RetInt(_DBRecNo(-1), 10); } FoxInfo myFoxInfo[] = { {"DBRECNO", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest GO 3 ? DBRECNO() GO 6 ? DBRECNO() USE ? DBRECNO() && returns -119 PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Jolly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" APPEND BLANK REPLACE ABC WITH "Good golly" APPEND BLANK REPLACE ABC WITH "Four score and" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00176. example.c link.exe @d:\temp\nmb00176. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED int _DBReplace(Locator FAR *fld, Value FAR *val) This example duplicates some of the functionality of the FoxPro command REPLACE (but works strictly on a single record at a time). (#include void FAR Example(ParamBlk FAR *parm) { _RetInt(_DBReplace(&parm->p[0].loc, &parm->p[1].val), 10); } FoxInfo myFoxInfo[] = { {"DBREPLACE", (FPFI) Example, 2, "R,?"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest ? DBREPLACE(@ABC, "Hello, world.") ? DBREPLACE(@ABC, 2) && returns -302 because field ABC is a character field PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00276. example.c link.exe @d:\temp\nmb00276. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _DBRewind(int workarea) This example calls _DBRewind() for the DBF in the current work area. This has the same effect as the FoxPro command GO TOP. #include void FAR Example(ParamBlk FAR *parm) { _RetInt(_DBRewind(-1), 10); } FoxInfo myFoxInfo[] = { {"DBREWIND", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest GO BOTTOM ? RECNO() ? DBREWIND() && returns 1 ? RECNO() && yes, we're at record 1 PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00221. example.c link.exe @d:\temp\nmb00221. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDflong _DBSeek(Value FAR *val) This example performs a seek on whatever index controls the order of the DBF in the current work area. Note the use of "?" in the FoxInfo structure which is required because we don't know the type of the index expression. #include void FAR Example(ParamBlk FAR *parm) { _DBSeek(&parm->p[0].val); } FoxInfo myFoxInfo[] = { {"DBSEEK", (FPFI) Example, 1, "?"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest INDEX ON ABC TAG ABC SET ORDER TO TAG ABC = DBSEEK("Hello, world") && seeks ABC = "Hello, world" LIST NEXT 1 USE PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00122. example.c link.exe @d:\temp\nmb00122. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _DBSkip(int workarea, long distance) This example duplicates the functionality of the FoxPro SKIP command.#include void FAR Example(ParamBlk FAR *pblk) { int RetCode; if ((RetCode = _DBSkip(-1, pblk->p[0].val.ev_long)) < 0) { _PutStr("\nError encountered in example program."); _Error(-RetCode); // _DBSkip() returns negative error code } _RetInt(RetCode, 10); } FoxInfo myFoxInfo[] = { {"DBSKIP", (FPFI) Example, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; ]SET LIBRARY TO example ON ERROR DO expectError DO CreateTest USE = DBSKIP(1) && _Error() called: no DBF in use USE test GO TOP = DBSKIP(-1) = DBSKIP(-1) && _Error() called: at top of file GO BOTT = DBSKIP(1) = DBSKIP(1) && _Error() called: at bottom of file ON ERROR PROCEDURE expectError ? "ERROR: " + MESSAGE() RETURN PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00236. example.c link.exe @d:\temp\nmb00236. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDDint _DBStatus(int workarea) This example displays the status of the DBF in the current work area. It checks each bit of information in value returned by _DBStatus() and displays an appropriate message to the screen. #include void FAR Example(ParamBlk FAR *parm) { int dbstatus = _DBStatus(-1); _PutStr("\nStatus of DBF in current work area:"); if (dbstatus & DB_BOF) _PutStr("\nBOF()"); if (dbstatus & DB_EOF) _PutStr("\nEOF()"); if (dbstatus & DB_RLOCKED) _PutStr("\nCurrent record is RLOCKed"); if (dbstatus & DB_FLOCKED) _PutStr("\nDatabase is FLOCKed"); if (dbstatus & DB_EXCLUSIVE) _PutStr("\nDatabase is open EXCLUSIVEly"); if (dbstatus & DB_READONLY) _PutStr("\nDatabase is READONLY"); } FoxInfo myFoxInfo[] = { {"DBSTATUS", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; VSET LIBRARY TO example = DBSTATUS() && displays status of DBF in current work area Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00282. example.c link.exe @d:\temp\nmb00282. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED+void _DBUnlock(int workarea) This example uses _DBUnLock() to unlock all records of the DBF in the current work area. The FoxPro code demonstrates it and verifies that it is working properly. #include void FAR xLockRecord(ParamBlk FAR *parm) { _DBLock(-1, DBL_RECORD); } void FAR xLockFile(ParamBlk FAR *parm) { _DBLock(-1, DBL_FILE); } void FAR xUnLockFile(ParamBlk FAR *parm) { _DBUnLock(-1); } FoxInfo myFoxInfo[] = { {"XRLOCK", (FPFI) xLockRecord, 0, ""}, {"XFLOCK", (FPFI) xLockFile, 0, ""}, {"XUNLOCK", (FPFI) xUnLockFile, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example DO CreateTest USE Test SHARED GO 2 = XRLOCK() LIST STAT && shows that record #2 is locked = XUNLOCK() LIST STAT && shows no records are locked = XFLOCK() LIST STAT && shows that whole DBF is locked = XUNLOCK() LIST STAT && shows no records are locked PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00215. example.c link.exe @d:\temp\nmb00215. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlong _DBUnwind(int workarea) This example calls _DBUnWind() for the DBF in the current work area. #include void FAR Example(ParamBlk FAR *parm) { _RetInt(_DBUnwind(-1), 10); } FoxInfo myFoxInfo[] = { {"DBUNWIND", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example DO CreateTest ? DBUNWIND() && returns new record # SKIP ? EOF() && now EOF() returns .T. PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURNSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00243. example.c link.exe @d:\temp\nmb00243. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDXint _DBWrite(int workarea) This example does a _DBReplace() using the two calling parameters, one a DBF field passed by reference, the other a value of the appropriate type. It does a LIST NEXT 1 before and after a call to _DBWrite(). #include void FAR Example(ParamBlk FAR *parm) { int RetValue; if (RetValue = _DBReplace(&parm->p[0].loc, &parm->p[1].val)) { _UserError("\n_DBReplace() failed"); } _Execute("LIST NEXT 1"); if (RetValue = _DBWrite(-1)) { _Error(-RetValue); } _Execute("LIST NEXT 1"); } FoxInfo myFoxInfo[] = { {"DBWRITE", (FPFI) Example, 2, "R,?"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00260. example.c link.exe @d:\temp\nmb00260. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED9void _DeActivateHandler(unsigned int) This example activates an event handler when the library is loaded. The event handler just prints a message and lets FoxPro process the message as it would normally. The event handler is deactivated when the library is unloaded. As in this example, _DeActivateHandler() is usually called from a CALLONUNLOAD function. Some more functional examples of event handling can be found in the EXAMPLES directory as EVENT.C and SWATCH.C. #include static int HandlerID; // // This is the routine that is registered as an event handler. // FAR EventHandler(WHandle theWindow, EventRec FAR *ev) { _PutStr("\nEventHandler() called."); return NO; // event still needs to be handled by FoxPro } FAR Activate() { HandlerID = _ActivateHandler(EventHandler); return 0; } // // When the library is unloaded we must deactivate the event handler // in a CALLONUNLOAD function. // FAR DeActivate() { _DeActivateHandler(HandlerID); return 0; } FoxInfo myFoxInfo[] = { {"ACTIVATE", (FPFI) Activate, CALLONLOAD, ""}, {"DEACTIVATE", (FPFI) DeActivate, CALLONUNLOAD, ""} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00119. example.c link.exe @d:\temp\nmb00119. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _DeActivateIdle(unsigned int) This example activates an idle event handler when the library is loaded. The idle event handler just prints a message. The idle event handler is deactivated when the library is unloaded. As in this example, _DeActivateIdle() is usually called from a CALLONUNLOAD function.#include static unsigned IdlerID; // // This is the routine that is registered as an idle event handler. // void FAR IdleHandler(WHandle wh, EventRec *ev) { _PutStr("\nIdleHandler() called."); } void FAR Activate(ParamBlk FAR *parm) { IdlerID = _ActivateIdle((FPFI) IdleHandler); } // // When the library is unloaded we must deactivate the idle event handler // in a CALLONUNLOAD function. // void FAR DeActivate(ParamBlk FAR *parm) { _DeActivateIdle(IdlerID); } FoxInfo myFoxInfo[] = { {"ACTIVATE", (FPFI) Activate, CALLONLOAD, ""}, {"DEACTIVATE", (FPFI) DeActivate, CALLONUNLOAD, ""} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00224. example.c link.exe @d:\temp\nmb00224. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _DeActivateMenu(MENUID menuid) This example activates and deactivates a menu several times.#include void FAR DeActMenuEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _Execute("WAIT WINDOW 'Menu activated'"); _DeActivateMenu(menuId); _Execute("WAIT WINDOW 'Menu deactivated'"); _ActivateMenu(menuId); _Execute("WAIT WINDOW 'Menu activated'"); _DeActivateMenu(menuId); _Execute("WAIT WINDOW 'Menu deactivated'"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) DeActMenuEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00143. example.c link.exe @d:\temp\nmb00143. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED!void _DefaultProcess(EventRec FAR *event) This example is a loop consisting of a call to _GetNextEvent() followed by a call to _DefaultProcess(). All events receive get their default processing. f#include void FAR Example(ParamBlk FAR *parm) { EventRec ev; int i; for (i = 0; i < 16; i++) { _GetNextEvent(&ev); _DefaultProcess(&ev); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00284. example.c link.exe @d:\temp\nmb00284. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _Dialog(int scheme, char FAR *body_text, char FAR *button1, char FAR *button2, char FAR*button3, int default, int escape) This example creates dialogs with three, two, one, and no buttons.$#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR dialogEx(ParamBlk FAR *parm) { int selection; selection = _Dialog(DIALOG_SCHEME, "Example dialog with 3 buttons.", "First", "Second", "Third", 2, 3); _PutStr("\nItem selected ="); putLong(selection); selection = _Dialog(DIALOG_SCHEME, "Example dialog with 2 buttons.", "First", "Second", 0, 2, 2); _PutStr("\nItem selected ="); putLong(selection); selection = _Dialog(DIALOG_SCHEME, "Example dialog with 1 button.", "First", (char *) 0, (char *) 0, 1, 1); _PutStr("\nItem selected ="); putLong(selection); selection = _Dialog(DIALOG_SCHEME, "Example dialog no buttons.", (char *) 0, (char *) 0, (char *) 0, 1, 2); _PutStr("\nItem selected ="); putLong(selection); } FoxInfo myFoxInfo[] = { {"DIALOGEX", (FPFI) dialogEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00076. example.c link.exe @d:\temp\nmb00076. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _DisposeItem(MENUID menuid, ITEMID itemid) This example creates a menu with three items and then uses _DisposeItem() to remove two of the items.#include void FAR DisposeItemEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _Execute("WAIT WINDOW 'Menu has three items'"); _DisposeItem(menuId, _GetItemId(menuId, 1)); _Execute("WAIT WINDOW 'Menu has two items'"); _DisposeItem(menuId, _GetItemId(menuId, 0)); _Execute("WAIT WINDOW 'Menu has one item'"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) DisposeItemEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00220. example.c link.exe @d:\temp\nmb00220. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _DisposeMenu(MENUID menuid) This example calls _DisposeMenu() after a menu selection has been made.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); _DisposeMenu(menuId); return 0; } void FAR activateMenu(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _OnSelection(menuId, -1, onSelection); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) activateMenu, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00258. example.c link.exe @d:\temp\nmb00258. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDDvoid _EdActive(WHANDLE, BOOL) This example opens an edit window for a file whose name is passed as a parameter and selects the first character. Using _EdActive() the example activates and then deactivates the selection.#include void FAR EdActiveEx(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFILENAME[parm->p[0].val.ev_length] = '\0'; wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdActive(wh, TRUE); _Execute("WAIT 'Selection active'"); _EdActive(wh, FALSE); _Execute("WAIT 'Selection inactive'"); } FoxInfo myFoxInfo[] = { {"EDACTIVE", (FPFI) EdActiveEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example fc = FCREATE("x", 0) FOR i = 1 TO 90 = FPUTS(fc, REPL(ALLT(STR(i)), i), i) ENDFOR = FCLOSE(fc) = EDACTIVE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00287. example.c link.exe @d:\temp\nmb00287. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _EdCloseFile(WHANDLE, int) This example opens a single file specified by a parameter for editing, deletes a character, and closes the edit session three times. The first time _EdCloseFile() is called with "save without asking," the second time with "save with asking," and the third time with "save as." Each time the return value of _EdCloseFile() is displayed.l#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 5; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; int retValue; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFILENAME[parm->p[0].val.ev_length] = '\0'; // // Open, delete a character, close "save without asking" // wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdDelete(wh); retValue = _EdCloseFile(wh, 0); // save without asking _PutStr("\n_EdCloseFile() ="); putLong(retValue); // // Open, delete a character, close "save with asking" // _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdDelete(wh); retValue = _EdCloseFile(wh, 1); // save with asking _PutStr("\n_EdCloseFile() ="); putLong(retValue); // // Open, delete a character, close "save as" // _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdDelete(wh); retValue = _EdCloseFile(wh, 2); // save as _PutStr("\n_EdCloseFile() ="); putLong(retValue); } FoxInfo myFoxInfo[] = { {"EDCLOSE", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDCLOSE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00176. example.c link.exe @d:\temp\nmb00176. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED=void _EdCopy(WHANDLE) This example opens a file specified by a parameter for editing, copies the first character to the clipboard using _EdCopy(), and pastes it after the second character using _EdPaste().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdCopy(wh); _EdSetPos(wh, 2); _EdPaste(wh); } FoxInfo myFoxInfo[] = { {"EDCOPY", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDCOPY("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00288. example.c link.exe @d:\temp\nmb00288. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED:void _EdCut(WHANDLE) This example opens a file specified by a parameter for editing, cuts the first character to the clipboard using _EdCut(), and pastes it after the second character using _EdPaste().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdCut(wh); _EdSetPos(wh, 2); _EdPaste(wh); } FoxInfo myFoxInfo[] = { {"EDCUT", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDCUT("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00177. example.c link.exe @d:\temp\nmb00177. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdDelete(WHANDLE) This example opens a file specified by a parameter for editing and deletes the first character in the file using _EdDelete().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdDelete(wh); } FoxInfo myFoxInfo[] = { {"EDDELETE", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDDELETE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00298. example.c link.exe @d:\temp\nmb00298. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDTEXT _EdGetChar(WHANDLE, EDPOS ) This example opens a file specified by a parameter for editing and displays to the screen the entire contents of the file.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; EDPOS edpos; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFILENAME[parm->p[0].val.ev_length] = '\0'; wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdGetEnv(wh, &EdEnv); for (edpos = 0; edpos <= EdEnv.length; edpos++) { _PutChr(_EdGetChar(wh, edpos)); } } FoxInfo myFoxInfo[] = { {"EDGETCHAR", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; *SET LIBRARY TO example = EDGETCHAR("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00285. example.c link.exe @d:\temp\nmb00285. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED%void _EdGetEnv(WHANDLE, *EDENV) This example opens an edit session for a file specified by a parameter and displays each field of the EDENV structure for that file as returned by _EdGetEnv().#include void putLong(unsigned long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 6; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdGetEnv(wh, &EdEnv); _PutStr("\nfilename: "); _PutStr(EdEnv.filename); _PutStr("\nlength: "); putLong(EdEnv.length); _PutStr("\nlenLimit: "); putLong(EdEnv.lenLimit); _PutStr("\ndirty: "); putLong(EdEnv.dirty); _PutStr("\nautoIndent: "); putLong(EdEnv.autoIndent); _PutStr("\nbackup: "); putLong(EdEnv.backup); _PutStr("\naddLineFeeds: "); putLong(EdEnv.addLineFeeds); _PutStr("\nautoCompile: "); putLong(EdEnv.autoCompile); _PutStr("\naddCtrlZ: "); putLong(EdEnv.addCtrlZ); _PutStr("\nsavePrefs: "); putLong(EdEnv.savePrefs); _PutStr("\ndragAndDrop: "); putLong(EdEnv.dragAndDrop); _PutStr("\nreadOnly: "); putLong(EdEnv.readOnly); _PutStr("\nstatus: "); putLong(EdEnv.status); _PutStr("\nlockPrefs: "); putLong(EdEnv.lockPrefs); _PutStr("\ninsertMode: "); putLong(EdEnv.insertMode); _PutStr("\nwrap: "); putLong(EdEnv.wrap); _PutStr("\nselStart: "); putLong(EdEnv.selStart); _PutStr("\nselEnd: "); putLong(EdEnv.selEnd); _PutStr("\nselAnchor: "); putLong(EdEnv.selAnchor); _PutStr("\njustMode: "); putLong(EdEnv.justMode); _PutStr("\ntabWidth: "); putLong(EdEnv.tabWidth); _PutStr("\nfontName: "); _PutStr(EdEnv.fontName); _PutStr("\nfontSize: "); putLong(EdEnv.fontSize); _PutStr("\nfontStyle: "); putLong(EdEnv.fontStyle); _PutStr("\nkind: "); putLong(EdEnv.kind); } FoxInfo myFoxInfo[] = { {"EDGETENV", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDGETENV("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00259. example.c link.exe @d:\temp\nmb00259. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED void putLong(unsigned long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 6; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDPOS edpos; EDLINE edlin, original; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); edpos = _EdGetLinePos(wh, 12); _PutStr("\n_EdGetLinePos(wh, 12) ="); putLong(edpos); original = edlin = _EdGetLineNum(wh, edpos); for (;;) { _PutStr("\n_EdGetLineNum(wh,"); putLong(edpos); _PutStr(") = "); putLong(edlin); if (edlin != original) { break; } edpos++; edlin = _EdGetLineNum(wh, edpos); } edpos = _EdGetLinePos(wh, 13); _PutStr("\n_EdGetLinePos(wh, 13) ="); putLong(edpos); } FoxInfo myFoxInfo[] = { {"EDGETLPOS", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; *SET LIBRARY TO example = EDGETLPOS("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00064. example.c link.exe @d:\temp\nmb00064. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED void putLong(unsigned long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 6; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDPOS edpos; EDLINE edlin, original; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); edpos = _EdGetLinePos(wh, 12); _PutStr("\n_EdGetLinePos(wh, 12) ="); putLong(edpos); original = edlin = _EdGetLineNum(wh, edpos); for (;;) { _PutStr("\n_EdGetLineNum(wh,"); putLong(edpos); _PutStr(") = "); putLong(edlin); if (edlin != original) { break; } edpos++; edlin = _EdGetLineNum(wh, edpos); } edpos = _EdGetLinePos(wh, 13); _PutStr("\n_EdGetLinePos(wh, 13) ="); putLong(edpos); } FoxInfo myFoxInfo[] = { {"EDGETLPOS", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; *SET LIBRARY TO example = EDGETLPOS("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00143. example.c link.exe @d:\temp\nmb00143. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDEDPOS _EdGetPos(WHANDLE) This example opens an edit session for a file specified by a parameter. After setting the current insertion point with _EdSetPos(), a call to _EdGetPos() is made to verify that it returns the insertion point. After selecting text with _EdSelect(), a call to _EdGetPos() is made to verify that it returns the anchor point. #include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 6; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDPOS edpos; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, 19); _PutStr("\n_EdSetPos(wh, 19)"); edpos = _EdGetPos(wh); _PutStr("\n_EdGetPos(wh) ="); putLong(edpos); _EdSelect(wh, 5, 12); _PutStr("\n_EdSelect(wh, 5, 12)"); edpos = _EdGetPos(wh); _PutStr("\n_EdGetPos(wh) ="); putLong(edpos); } FoxInfo myFoxInfo[] = { {"EDGETPOS", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDGETPOS("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00265. example.c link.exe @d:\temp\nmb00265. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdGetStr(WHANDLE, EDPOS, EDPOS, TEXT *) This example is an API routine takes a file name as a parameter and returns the file's first 16 bytes. #include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char FAR *buffer; char FAR *pFileName; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFileName = _HandToPtr(parm->p[0].val.ev_handle); pFileName[parm->p[0].val.ev_length] = '\0'; wh = _EdOpenFile(pFileName, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); if ((buffer = _Alloca(17)) == 0) { _Error(182); // "Insufficient memory" } _EdGetStr(wh, 1, 16, buffer); buffer[16] = '\0'; _RetChar(buffer); } FoxInfo myFoxInfo[] = { {"EDGETSTR", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; XSET LIBRARY TO example ? EDGETSTR("x") && returns the first 16 characters of file "x" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00302. example.c link.exe @d:\temp\nmb00302. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdIndent(WHANDLE, int) This example opens an edit session for a file specified by a parameter and indents lines 12 and 13 by a single tab stop.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, _EdGetLinePos(wh, 12), _EdGetLinePos(wh, 14)); _EdIndent(wh, 1); } FoxInfo myFoxInfo[] = { {"EDINDENT", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDINDENT("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00240. example.c link.exe @d:\temp\nmb00240. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdInsert(WHANDLE, TEXT *, BYTES) This example opens an edit session for a file specified by a parameter and inserts the line of text "Hello, world" as the new thirteenth line.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); } FoxInfo myFoxInfo[] = { {"EDINSERT", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDINSERT("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00189. example.c link.exe @d:\temp\nmb00189. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED1int _EdLastError(WHANDLE) This example displays the error code returned by _EdLastError() after a number of editor operations. The name of a file to work on is the parameter to the API function. #include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { char FAR *pFileName; WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFileName = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); pFileName[parm->p[0].val.ev_length] = '\0'; wh = _EdOpenFile(pFileName, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); // // Position past end of file // _EdGetEnv(wh, &EdEnv); _EdSetPos(wh, EdEnv.length + 128); _PutStr("\n_EdLastError() ="); putLong(_EdLastError(wh)); // // _EdCopy() with no selection // _EdSetPos(wh, 1); _EdCopy(wh); _PutStr("\n_EdLastError() ="); putLong(_EdLastError(wh)); // // _EdScrollToSel() with no selection // _EdScrollToSel(wh, TRUE); _PutStr("\n_EdLastError() ="); putLong(_EdLastError(wh)); } FoxInfo myFoxInfo[] = { {"EDLASTERR", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; cSET LIBRARY TO example = EDLASTERR("x") && displays _EdLastError() after operations on file "x" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00149. example.c link.exe @d:\temp\nmb00149. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDWHANDLE _EdOpenFile(TEXT *filename) This examples opens an editor session for a file specified by a parameter.p#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"EDOPEN", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; OSET LIBRARY TO example = EDOPEN("x") && opens editor session for file "x" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00237. example.c link.exe @d:\temp\nmb00237. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED=void _EdPaste(WHANDLE) This example opens a file specified by a parameter for editing, copies the first character to the clipboard using _EdCopy(), and pastes it after the second character using _EdPaste().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdCopy(wh); _EdSetPos(wh, 2); _EdPaste(wh); } FoxInfo myFoxInfo[] = { {"EDCOPY", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; (SET LIBRARY TO example = EDCOPY("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00297. example.c link.exe @d:\temp\nmb00297. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDBOOL _EdPosInView(WHANDLE, EDPOS) This example opens a file specified by a parameter for editing. After scrolling to the top of the file, _EdPosInView() is called to check whether the top of file and bottom of file are in view and the results are printed to the screen. Then it scrolls to the bottom of the file, and again _EdPosInView() is called to check whether the top of file and bottom of file are in view.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdGetEnv(wh, &EdEnv); _EdScrollToPos(wh, 0, FALSE); _PutStr("\n_EdScrollToPos(wh, 0)"); _PutStr("\n_EdPosInView(wh, 0) ="); putLong(_EdPosInView(wh, 0)); _PutStr("\n_EdPosInView(wh, EdEnv.length) ="); putLong(_EdPosInView(wh, EdEnv.length)); _EdScrollToPos(wh, EdEnv.length, FALSE); _PutStr("\n_EdScrollToPos(wh, EdEnv.length)"); _PutStr("\n_EdPosInView(wh, 0) ="); putLong(_EdPosInView(wh, 0)); _PutStr("\n_EdPosInView(wh, EdEnv.length) ="); putLong(_EdPosInView(wh, EdEnv.length)); } FoxInfo myFoxInfo[] = { {"POSINVIEW", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; *SET LIBRARY TO example = POSINVIEW("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00216. example.c link.exe @d:\temp\nmb00216. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDFvoid _EdRedo(WHANDLE) This example opens a file specified by a parameter for editing. After inserting a new line, the insertion is backed out using _EdUndo() and then _EdRedo() is called restore the inserted line.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _Execute("WAIT 'New line inserted. Press any key to undo.'"); _EdUndo(wh); _Execute("WAIT 'Insertion undone. Press any key to redo.'"); _EdRedo(wh); } FoxInfo myFoxInfo[] = { {"EDREDO", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDREDO("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00093. example.c link.exe @d:\temp\nmb00093. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED[void _EdRevert(WHANDLE) This example opens a file specified by a parameter for editing. After some editing, insertion of a new line, indenting of two lines, and deletion of two lines, the changes are backed out by a call to _EdRevert().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16)); _EdIndent(wh, 1); _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12)); _EdDelete(wh); _EdRevert(wh); } FoxInfo myFoxInfo[] = { {"EDREVERT", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDREVERT("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00233. example.c link.exe @d:\temp\nmb00233. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdSave(WHANDLE) This example opens a file specified by a parameter for editing. Some editing is performed, insertion of a new line, indenting of two lines, and deletion of two lines. After the insertion of the new line but before the indentation and deletion, _EdSave() is called. Three calls to _EdUndo() are made in an attempt to undo all of the editing, but the insertion made before the call to _EdSave() cannot be undone. Two more edit operations are performed with a call to _EdSave() between them. _EdRevert() is called, but it too can only back out changes made since the last _EdSave().+#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _EdSave(wh); _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16)); _EdIndent(wh, 1); _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12)); _EdDelete(wh); _Execute("WAIT 'Press any key to undo changes.'"); _EdUndo(wh); // undo deletion _EdUndo(wh); // undo indent _EdUndo(wh); // attempt to undo insertion, but can't _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16)); _EdIndent(wh, 1); _EdSave(wh); _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12)); _EdDelete(wh); _EdRevert(wh); // undoes deletion } FoxInfo myFoxInfo[] = { {"EDSAVE", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDSAVE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00187. example.c link.exe @d:\temp\nmb00187. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED;void _EdScrollToPos(WHANDLE, EDPOS , BOOL) This example opens a file specified by a parameter for editing. After scrolling to the top of the file by calling _EdScrollToPos(), _EdPosInView() is called to check whether the top of file and bottom of file are in view and the results are printed to the screen. Then it scrolls to the bottom of the file by calling _EdScrollToPos(), and again _EdPosInView() is called to check whether the top of file and bottom of file are in view.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdGetEnv(wh, &EdEnv); _EdScrollToPos(wh, 0, FALSE); _PutStr("\n_EdScrollToPos(wh, 0)"); _PutStr("\n_EdPosInView(wh, 0) ="); putLong(_EdPosInView(wh, 0)); _PutStr("\n_EdPosInView(wh, EdEnv.length) ="); putLong(_EdPosInView(wh, EdEnv.length)); _EdScrollToPos(wh, EdEnv.length, FALSE); _PutStr("\n_EdScrollToPos(wh, EdEnv.length)"); _PutStr("\n_EdPosInView(wh, 0) ="); putLong(_EdPosInView(wh, 0)); _PutStr("\n_EdPosInView(wh, EdEnv.length) ="); putLong(_EdPosInView(wh, EdEnv.length)); } FoxInfo myFoxInfo[] = { {"POSINVIEW", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; *SET LIBRARY TO example = POSINVIEW("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00151. example.c link.exe @d:\temp\nmb00151. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdScrollToSel(WHANDLE, BOOL) This example opens a file specified by a parameter for editing. A selection is made near the bottom of the file. After a key press in response to a WAIT, the edit window is scrolled to the selection by calling _EdScrollToSel(). The same selection, scroll to selection operation is done with a selection near the top of the file.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READONLY); _HUnLock(parm->p[0].val.ev_handle); _EdScrollToPos(wh, 0, TRUE); _EdGetEnv(wh, &EdEnv); _EdSelect(wh, EdEnv.length - 16, EdEnv.length); _PutStr("\nMade selection at end of file."); _Execute("WAIT 'Press any key to scroll to selection.'"); _EdScrollToSel(wh, TRUE); _EdSelect(wh, 1, 16); _PutStr("\nMade selection at end of file."); _Execute("WAIT 'Press any key to scroll to selection.'"); _EdScrollToSel(wh, TRUE); } FoxInfo myFoxInfo[] = { {"TOSEL", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; &SET LIBRARY TO example = TOSEL("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00190. example.c link.exe @d:\temp\nmb00190. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDfvoid _EdSelect(WHANDLE, EDPOS, EDPOS) This example opens a file specified by a parameter for editing, selects the first character using _EdSelect(), copies the selection to the clipboard using _EdCopy(), and pastes it after the second character using _EdPaste().#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSelect(wh, 0, 1); _EdCopy(wh); _EdSetPos(wh, 2); _EdPaste(wh); } FoxInfo myFoxInfo[] = { {"EDCOPY", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 'SET LIBRARY TO example = EDCOPY("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00185. example.c link.exe @d:\temp\nmb00185. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _EdSendKey(WHANDLE, int) This example opens a file specified by a parameter for editing. A line of text, "Hello, World", is inserted by sending the individual characters with _EdSendKey(). An ASCII escape character is inserted using _EdSendKey(). Notice that it is not interpreted as "discard edit session."#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); // // Insert a line of text using _EdSendKey() // _EdSetPos(wh, 0); _EdSendKey(wh, 'H'); _EdSendKey(wh, 'e'); _EdSendKey(wh, 'l'); _EdSendKey(wh, 'l'); _EdSendKey(wh, 'o'); _EdSendKey(wh, ','); _EdSendKey(wh, ' '); _EdSendKey(wh, 'W'); _EdSendKey(wh, 'o'); _EdSendKey(wh, 'r'); _EdSendKey(wh, 'l'); _EdSendKey(wh, 'd'); _EdSendKey(wh, '.'); _EdSendKey(wh, 0x0d); // carriage return _EdSendKey(wh, 0x0a); // line feed _EdSendKey(wh, 0x1b); // esc char code is inserted in file } FoxInfo myFoxInfo[] = { {"SENDKEY", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; (SET LIBRARY TO example = SENDKEY("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00176. example.c link.exe @d:\temp\nmb00176. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDTvoid _EdSetEnv(WHANDLE, *EDENV) This example opens a file specified by a parameter for editing. After indent the first two lines of the file, _EdSetEnv() is used to change the size of a tab stop to 6 characters and then to 9 characters.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDENV EdEnv; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdGetEnv(wh, &EdEnv); _EdSelect(wh, _EdGetLinePos(wh, 1), _EdGetLinePos(wh, 3)); _EdIndent(wh, 1); _Execute("WAIT 'Press any key to change tabs to 6 characters.'"); EdEnv.tabWidth = 6; _EdSetEnv(wh, &EdEnv); _Execute("WAIT 'Press any key to change tabs to 9 characters.'"); EdEnv.tabWidth = 9; _EdSetEnv(wh, &EdEnv); } FoxInfo myFoxInfo[] = { {"EDSETENV", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDSETENV("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00288. example.c link.exe @d:\temp\nmb00288. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDqvoid _EdSetPos(WHANDLE, EDPOS) This example opens a file specified by a parameter for editing. Using _EdSetPos() the insertion point is set to position 19 of the file. _EdGetPos() is called and some text is inserted to verify that the insertion point has been set.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 6; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDPOS edpos; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, 19); _PutStr("\n_EdSetPos(wh, 19)"); edpos = _EdGetPos(wh); _PutStr("\n_EdGetPos(wh) ="); putLong(edpos); _EdInsert(wh, "*** Inserted at EDPOS = 19 ***", _StrLen("*** Inserted at EDPOS = 19 ***")); } FoxInfo myFoxInfo[] = { {"EDSETPOS", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDSETPOS('x') ;Setting environment for using Microsoft Visual C++ tools.  void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; EDPOS edpos; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _Execute("WAIT 'Using _EdSkipLines() to select lines 3 and 4'"); edpos = _EdSkipLines(wh, 0, 2); // skip to two lines from top _EdSelect(wh, edpos, _EdSkipLines(wh, edpos, 2)); // select next two lines } FoxInfo myFoxInfo[] = { {"SKIPLINE", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = SKIPLINE("x") ;Setting environment for using Microsoft Visual C++ tools. Fvoid _EdUndo(WHANDLE) This example opens a file specified by a parameter for editing. After inserting a new line, the insertion is backed out using _EdUndo() and then _EdRedo() is called restore the inserted line.#include void FAR Example(ParamBlk FAR *parm) { #define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } pFILENAME[parm->p[0].val.ev_length] = '\0'; _HLock(parm->p[0].val.ev_handle); wh = _EdOpenFile(pFILENAME, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _Execute("WAIT 'New line inserted. Press any key to undo.'"); _EdUndo(wh); _Execute("WAIT 'Insertion undone. Press any key to redo.'"); _EdRedo(wh); } FoxInfo myFoxInfo[] = { {"EDREDO", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; )SET LIBRARY TO example = EDREDO("x") ;Setting environment for using Microsoft Visual C++ tools. void _EdUndoOn(WHANDLE, BOOL) This example shows how _EdUndoOn() is used to group edit operations that can be undone as a group. #include #define TRUE 1 #define FALSE 0 void FAR Example(ParamBlk FAR *parm) { char FAR *pFileName; WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pFileName = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); pFileName[parm->p[0].val.ev_length] = '\0'; wh = _EdOpenFile(pFileName, FO_READWRITE); _HUnLock(parm->p[0].val.ev_handle); _EdUndoOn(wh, TRUE); // start undo group _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _EdSelect(wh, _EdGetLinePos(wh, 14), _EdGetLinePos(wh, 16)); _EdIndent(wh, 1); _EdUndoOn(wh, FALSE); // end undo group _EdUndoOn(wh, TRUE); // start another undo group _EdSelect(wh, _EdGetLinePos(wh, 9), _EdGetLinePos(wh, 12)); _EdDelete(wh); _EdSetPos(wh, _EdGetLinePos(wh, 13)); _EdInsert(wh, "Hello, world\r\n", _StrLen("Hello, world\r\n")); _Execute("WAIT 'Press any key to undo changes.'"); _EdUndoOn(wh, TRUE); // undoes to start of undo group } FoxInfo myFoxInfo[] = { {"EDUNDOON", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; ;SET LIBRARY TO example = EDUNDOON("x") && edit file "x" ;Setting environment for using Microsoft Visual C++ tools. void _Error(int code) This example calls _Error() when _DBSkip() returns an error code. The FoxPro code shows how to cause _Error() to be called.#include void FAR Example(ParamBlk FAR *pblk) { int RetCode; if ((RetCode = _DBSkip(-1, pblk->p[0].val.ev_long)) < 0) { _PutStr("\nError encountered in example program."); _Error(-RetCode); // _DBSkip() returns negative error code } _RetInt(RetCode, 10); } FoxInfo myFoxInfo[] = { {"DBSKIP", (FPFI) Example, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; bSET LIBRARY TO example DO CreateTest ON ERROR DO expectError USE = DBSKIP(1) && _Error() called: no DBF in use USE test GO TOP = DBSKIP(-1) = DBSKIP(-1) && _Error() called: at top of file GO BOTT = DBSKIP(1) = DBSKIP(1) && _Error() called: at bottom of file ON ERROR PROCEDURE expectError ? "ERROR: " + MESSAGE() RETURN PROCEDURE CreateTest CREATE TABLE test (ABC C(20)) APPEND BLANK REPLACE ABC WITH "Golly month of" APPEND BLANK REPLACE ABC WITH "A twelveth of" APPEND BLANK REPLACE ABC WITH "Hello, world" APPEND BLANK REPLACE ABC WITH "When in the" GO TOP RETURN;Setting environment for using Microsoft Visual C++ tools. int _ErrorInfo(int code, char FAR *message) This example displays the information returned by _ErrorInfo().j#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR ErrorInfo(ParamBlk FAR *parm) { int ext; char FAR *message; if ((message =_Alloca(128)) == 0) { _Error(182); // "Insufficient memory" } ext = _ErrorInfo((int) parm->p[0].val.ev_long, message); _PutChr('\n'); putLong(ext); _PutStr(" "); _PutStr(message); } FoxInfo myFoxInfo[] = { {"ERRORINFO", (FPFI) ErrorInfo, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 8SET LIBRARY TO example = ERRORINFO(0) = ERRORINFO(1) ;Setting environment for using Microsoft Visual C++ tools. int _Evaluate(Value FAR *res, char FAR *expr) This example replicates the functionality of FoxPro's EVAL() function.#include void FAR EvaluateEx(ParamBlk FAR *parm) { char FAR *expr; Value result; // // Null terminate character string // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); expr = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); expr[parm->p[0].val.ev_length] = '\0'; _Evaluate(&result, expr); _RetVal(&result); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"XEVAL", (FPFI) EvaluateEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; YSET LIBRARY TO example ? XEVAL("2 + 3") ? XEVAL("'a' + 'b'") ? XEVAL("SIN(PI()/2))") ;Setting environment for using Microsoft Visual C++ tools. int _Execute(char FAR *stmt) This example uses _Execute() to execute the FoxPro command string passed as an argument to the API function.r#include void FAR ExecuteEx(ParamBlk FAR *parm) { char FAR *cmd; // // Null terminate character string // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); cmd = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); cmd[parm->p[0].val.ev_length] = '\0'; _Execute(cmd); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"EXEC", (FPFI) ExecuteEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; PSET LIBRARY TO example = EXEC("? 'Hello, world.'") = EXEC("DISPLAY STATUS") ;Setting environment for using Microsoft Visual C++ tools. int _FCHSize(FCHAN chan, long length) This example creates a file TEMP.TXT and sets its size to 8192 using _FCHSize().T#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan = _FCreate("temp.txt", FC_NORMAL); _FCHSize(fchan, 8196); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FCHSIZE", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FClose(FCHAN chan) This example creates a file TEMP.TXT, sets its size to 8192, and closes it using _FClose().T#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan = _FCreate("temp.txt", FC_NORMAL); _FCHSize(fchan, 8196); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FCHSIZE", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. =int _FCopy(FCHAN dc, long dpos, FCHAN sc, long spos, long len) This example creates two files. It writes the text "Hello, world" to one of these files and then copies the contents of this file, beginning with the third byte, to the other file. G#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan1, fchan2; int len; fchan1 = _FCreate("temp1.txt", FC_NORMAL); _FPuts(fchan1, "Hello, world."); _FFlush(fchan1); len = _FSeek(fchan1, 0, FS_FROMEOF); // determine length of file fchan2 = _FCreate("temp2.txt", FC_NORMAL); _FCopy(fchan2, 0, fchan1, 2, len - 2); _FClose(fchan1); _FClose(fchan2); } FoxInfo myFoxInfo[] = { {"FCOPY", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. FCHAN _FCreate(char FAR *filename, int mode) This example uses _FCreate() to create a number of files using the various mode flags of _FCreate().#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; fchan = _FCreate("normal.tmp", FC_NORMAL); _FClose(fchan); fchan = _FCreate("readonly.tmp", FC_READONLY); _FClose(fchan); fchan = _FCreate("hidden.tmp", FC_HIDDEN); _FClose(fchan); fchan = _FCreate("system.tmp", FC_SYSTEM); _FClose(fchan); fchan = _FCreate("temp.tmp", FC_TEMPORARY); _FClose(fchan); fchan = _FCreate("multi.tmp", FC_SYSTEM | FC_READONLY); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FCREATE", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FEOF(FCHAN chan) This example creates a file and sets its length to 8192. Then it seeks to the beginning of the file and calls _FEOF(), which should return 0 (FALSE). Next it seeks to the end of the file and again calls _FEOF(), which should this time return 1 (TRUE).#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { FCHAN fchan = _FCreate("temp.txt", FC_NORMAL); _FCHSize(fchan, 8196); _FFlush(fchan); _FSeek(fchan, 0, FS_FROMBOF); _PutStr("\n_FSeek(fchan, 0, FS_FROMBOF)"); _PutStr("\n_FEOF(fchan) ="); putLong(_FEOF(fchan)); _FSeek(fchan, 0, FS_FROMEOF); _PutStr("\n_FSeek(fchan, 0, FS_FROMEOF)"); _PutStr("\n_FEOF(fchan) ="); putLong(_FEOF(fchan)); } FoxInfo myFoxInfo[] = { {"FEOF", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. *int _FError(void) This example attempts to _FOpen() a file called "nofile.abc" which presumably does not exists. It then calls _FError(), which should return 2 for "file not found."#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { FCHAN fchan = _FOpen("nofile.abc", FC_READONLY); _PutStr("\nAttempted to _FOpen() a file which does not exist."); _PutStr("\n_FError() ="); putLong(_FError()); } FoxInfo myFoxInfo[] = { {"FERROR", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FFlush(FCHAN chan) This example on loading the library creates a file and sets its length to 8192. Doing a DIR temp.txt at the Command shows that the size of the file on disk is still 0. However, after doing the = XFFLUSH(), issuing a DIR temp.tmp shows that the file on disk reflects the _FCHSize() call and shows a file size of 8192.#include static FCHAN fchan; void FAR CreateIt(ParamBlk FAR *parm) { fchan = _FCreate("temp.txt", FC_NORMAL); _FCHSize(fchan, 8196); } void FAR FFlushEx(ParamBlk FAR *parm) { _FFlush(fchan); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) CreateIt, CALLONLOAD, ""}, {"XFFLUSH", (FPFI) FFlushEx, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; xSET LIBRARY TO example DIR temp.tmp && size on disk is still 0 = XFFLUSH() DIR temp.tmp && size on disk is 8192 ;Setting environment for using Microsoft Visual C++ tools. int _FGets(FCHAN chan, char FAR *buffer, int maxlen) This example opens a file specified by a parameter and reads each line from the file with _FGets() and displays it.#include #define BUFFSIZE 256 static char lineBuffer[BUFFSIZE]; void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; // // Null terminate file name // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) [parm->p[0].val.ev_length] = '\0'; if ((fchan = _FOpen((char FAR *) _HandToPtr(parm->p[0].val.ev_handle), FC_NORMAL)) < 0) { _UserError("Could not open file."); } _HUnLock(parm->p[0].val.ev_handle); while (!_FEOF(fchan)) { _FGets(fchan, lineBuffer, BUFFSIZE); _PutStr(lineBuffer); _PutChr('\n'); } _FClose(fchan); } FoxInfo myFoxInfo[] = { {"XFGETS", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; }SET LIBRARY TO example fc = FCREATE("x", 0) = FPUTS(fc, REPL("X", 512), 512) = FCLOSE(fc) = XFGETS("x") DELETE FILE x;Setting environment for using Microsoft Visual C++ tools. _long _FindMemo(Locator FAR *fld) This example retrieves the contents of a memo field. _FindMemo() is used to find the location of the memo contents within the memo file. We _FSeek() to this location and _FRead() _MemoSize() bytes from the memofile.r#include void FAR FindMemoEx(ParamBlk FAR *parm) { Locator FAR *memoFldLoc; FCHAN fchMemo; char FAR *memoContents; int memoLen; long loc; if ((fchMemo = _MemoChan(-1)) == -1) { _UserError("_MemoChan() failed"); } memoFldLoc = &parm->p[0].loc; if ((loc = _FindMemo(memoFldLoc)) < 0) { _UserError("_FindMemo() failed"); } if ((memoLen = _MemoSize(memoFldLoc)) < 0) { _UserError("_MemoSize() failed"); } if ((memoContents = _Alloca(memoLen + 1)) == 0) { _Error(182); // "Insufficient memory" } _FSeek(fchMemo, loc, FS_FROMBOF); _FRead(fchMemo, memoContents, memoLen); memoContents[memoLen] = '\0'; _RetChar(memoContents); } FoxInfo myFoxInfo[] = { {"GETMEMO", (FPFI) FindMemoEx, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example CREATE TABLE WMemo (MemoField M) APPEND BLANK REPLACE MemoField WITH "Hello, World." ? GETMEMO(@MemoField) ;Setting environment for using Microsoft Visual C++ tools. int _FindVar(NTI nti, int where, Locator FAR *loc) This example does things "takes the long way home" in displaying the value of a FoxPro variable.c#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR NameTableIndexEx(ParamBlk FAR *parm) { NTI nti; char FAR *name; Locator loc; Value val; // // Null terminate character string, name of variable // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); name[parm->p[0].val.ev_length] = '\0'; nti = _NameTableIndex(name); _FindVar(nti, 0, &loc); _Load(&loc, &val); _PutValue(&val); } FoxInfo myFoxInfo[] = { {"QMARK", (FPFI) NameTableIndexEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FindWindow(WHANDLE FAR *wh, Point pt) This example waits for a left mouse button click and then using _FindWindow() gets the window handle for the mouse down position. #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MyFindWindowEx(ParamBlk FAR *parm) { WHANDLE wh; Point mousePos; int where; // // Get mouse position when left button goes down // while (_InKey(0, MOUSEACTIVE | HIDECURSOR) != 151); while (!_MousePos(&mousePos)); switch (where = _FindWindow(&wh, mousePos)) { case inBorder: _PutStr("\nMouse down inBorder"); break; case inHelp: _PutStr("\nMouse down inHelp"); break; case inContent: _PutStr("\nMouse down inContent"); break; case inDrag: _PutStr("\nMouse down inDrag"); break; case inGrow: _PutStr("\nMouse down inGrow"); break; case inGoAway: _PutStr("\nMouse down inGoAway"); break; case inZoom: _PutStr("\nMouse down inZoom"); break; case inVUpArrow: _PutStr("\nMouse down inVUpArrow"); break; case inVDownArrow: _PutStr("\nMouse down inVDownArrow"); break; case inVPageUp: _PutStr("\nMouse down inVPageUp"); break; case inVPageDown: _PutStr("\nMouse down inVPageDown"); break; case inVThumb: _PutStr("\nMouse down inVThumb"); break; case inHUpArrow: _PutStr("\nMouse down inHUpArrow"); break; case inHDownArrow: _PutStr("\nMouse down inHDownArrow"); break; case inHPageUp: _PutStr("\nMouse down inHPageUp"); break; case inHPageDown: _PutStr("\nMouse down inHPageDown"); break; case inHThumb: _PutStr("\nMouse down inHThumb"); break; case inMenuBar: _PutStr("\nMouse down inMenuBar"); break; default: _PutStr("\nMouse down someplace else"); break; } _GlobalToLocal(&mousePos, wh); _PutStr("\nPosition relative to window:"); putLong(mousePos.v, 5); _PutChr(' '); putLong(mousePos.h, 5); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) MyFindWindowEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 5? "Click mouse on a window" SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FindWindowP(WHANDLE FAR *wh, Point pt) This example waits for a left mouse button click and then using _FindWindowP() gets the window handle for the mouse down position. #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MyFindWindowEx(ParamBlk FAR *parm) { WHANDLE wh; Point mousePos; int where; // // Get mouse position when left button goes down // while (_InKey(0, MOUSEACTIVE | HIDECURSOR) != 151); while (!_MousePosP(&mousePos)); switch (where = _FindWindowP(&wh, mousePos)) { case inBorder: _PutStr("\nMouse down inBorder"); break; case inHelp: _PutStr("\nMouse down inHelp"); break; case inContent: _PutStr("\nMouse down inContent"); break; case inDrag: _PutStr("\nMouse down inDrag"); break; case inGrow: _PutStr("\nMouse down inGrow"); break; case inGoAway: _PutStr("\nMouse down inGoAway"); break; case inZoom: _PutStr("\nMouse down inZoom"); break; case inVUpArrow: _PutStr("\nMouse down inVUpArrow"); break; case inVDownArrow: _PutStr("\nMouse down inVDownArrow"); break; case inVPageUp: _PutStr("\nMouse down inVPageUp"); break; case inVPageDown: _PutStr("\nMouse down inVPageDown"); break; case inVThumb: _PutStr("\nMouse down inVThumb"); break; case inHUpArrow: _PutStr("\nMouse down inHUpArrow"); break; case inHDownArrow: _PutStr("\nMouse down inHDownArrow"); break; case inHPageUp: _PutStr("\nMouse down inHPageUp"); break; case inHPageDown: _PutStr("\nMouse down inHPageDown"); break; case inHThumb: _PutStr("\nMouse down inHThumb"); break; case inMenuBar: _PutStr("\nMouse down inMenuBar"); break; default: _PutStr("\nMouse down someplace else"); break; } _GlobalToLocalP(&mousePos, wh); _PutStr("\nPosition relative to window:"); putLong(mousePos.v, 5); _PutChr(' '); putLong(mousePos.h, 5); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)MyFindWindowEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example;Setting environment for using Microsoft Visual C++ tools. FCHAN _FOpen(char FAR *filename, int mode) This example creates a test file. It then opens it FO_READONLY and attempts to write to it. As a result _FError() should return 5 for "Access denied." Next, the example opens the test file FO_WRITEONLY and attempts to read from it. Again, _FError() should return 5.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } #define BUFFSIZE 256 static char lineBuffer[BUFFSIZE]; void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; fchan = _FCreate("temp.tmp", FC_NORMAL); _FCHSize(fchan, 8192); _FClose(fchan); fchan = _FOpen("temp.tmp", FO_READONLY); _FPuts(fchan, "Hello, world"); _PutStr("\nAttempt to _FPuts() to file _FOpen()d FO_READONLY"); _PutStr("\n_FError() ="); putLong(_FError()); _FClose(fchan); fchan = _FOpen("temp.tmp", FO_WRITEONLY); _FGets(fchan, lineBuffer, BUFFSIZE); _PutStr("\nAttempt to _FGets() from file _FOpen()d FO_WRITEONLY"); _PutStr("\n_FError() ="); putLong(_FError()); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FOPEN", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FPuts(FCHAN chan, char FAR *buffer) This example creates a file and writes the text "Hello, world" to the file using _FPuts().g#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; fchan = _FCreate("temp.tmp", FC_NORMAL); _FPuts(fchan, "Hello, world."); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FPUTS", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _FRead(FCHAN chan, char FAR *buffer, int length) This example creates a test file and gives it some contents. It then attempts to read 32 bytes from the file using _FRead().#include #define BUFFSIZE 32 static char buffer[BUFFSIZE]; void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; int bytesRead; fchan = _FCreate("temp.tmp", FC_NORMAL); _FPuts(fchan, "Hello, world."); _FPuts(fchan, "Hello, world."); _FPuts(fchan, "Hello, world."); _FPuts(fchan, "Hello, world."); _FPuts(fchan, "Hello, world."); _FSeek(fchan, 0, FS_FROMBOF); bytesRead = _FRead(fchan, buffer, BUFFSIZE - 1); buffer[bytesRead] = '\0'; _PutStr(buffer); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FREAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. -void _FreeHand(MHANDLE hand) This example allocates 1024 blocks of 16384 byte memory blocks (for a total of 16 Meg), freeing the previous memory block using _FreeHand() before allocating the next.#include void FAR Example(ParamBlk FAR *parm) { MHANDLE mh; int i; for (i = 0; i < 1024; i++) { if ((mh = _AllocHand(16384)) == 0) { _Error(182); // "Insufficient memory" } _FreeHand(mh); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. long _FSeek(FCHAN chan, long position, int mode) This example consists of one API routine which takes two parameters, a file name and an integer. It opens the file. Calling _FSeek() using the the FS_FROMBOF flag, it seeks the position specified by the integer parameter, and reads a single byte from the file at that position. V#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; char x; // // Null terminate file name // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) [parm->p[0].val.ev_length] = '\0'; if ((fchan = _FOpen((char FAR *) _HandToPtr(parm->p[0].val.ev_handle), FC_NORMAL)) < 0) { _UserError("Could not open file."); } _HUnLock(parm->p[0].val.ev_handle); _FSeek(fchan, parm->p[1].val.ev_long, FS_FROMBOF); _FRead(fchan, &x, 1); _RetInt(x, 10); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"XFSEEK", (FPFI) Example, 2, "C,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example fc = FCREATE("x", 0) = FPUTS(fc, "abcdefghijklmnopqrstuvwxyz", 26) = FCLOSE(fc) ? XFSEEK("x", 2) && displays 2nd byte of file x as an integer ? XFSEEK("x", 4) && displays 2nd byte of file x as an integer DELETE FILE x ;Setting environment for using Microsoft Visual C++ tools. int _FWrite(FCHAN chan, char FAR *buffer, int length) This example creates a test file and writes some data to it using _FWrite().#include void FAR Example(ParamBlk FAR *parm) { FCHAN fchan; fchan = _FCreate("temp.tmp", FC_NORMAL); _FWrite(fchan, "Hello, world.", _StrLen("Hello, world.")); _FWrite(fchan, "\xd\xa", 2); _FWrite(fchan, "1234567890", 10); _FClose(fchan); } FoxInfo myFoxInfo[] = { {"FWRITE", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. unsigned int _GetHandSize(MHANDLE hand) This example allocates memory blocks of various size from 1 to 2**15 and prints out the value returned by _GetHandSize() for these allocations. Notice that the value returned by _GetHandSize() is only sometimes exactly equal to the requested size; usually it is a bit more. #include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 5; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { MHANDLE mh; unsigned int allocSize; for (allocSize = 1;; allocSize *= 2) { if ((mh = _AllocHand(allocSize)) == 0) { _Error(182); // "Insufficient memory" } _PutStr("\n_AllocHand("); putLong(allocSize); _PutStr(")"); _PutStr("\n_GetHandSize() ="); putLong(_GetHandSize(mh)); _FreeHand(mh); if (allocSize == 32768) { break; } } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. int _GetItemCmdKey(MENUID menuid, ITEMID itemid, char FAR *text) This example creates a menu with three items, setting up a keyboard short cut for each item. It uses _GetItemCmdKey() to display the short cut keys.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetItemCmdKeyEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; char FAR *shortcutString; int intKeyCode; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); _SetItemCmdKey(menuId, itemId, altKey | 0x78, "Alt+1"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); _SetItemCmdKey(menuId, itemId, altKey | 0x79, "Alt+2"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); _SetItemCmdKey(menuId, itemId, altKey | 0x7a, "Alt+3"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); if ((shortcutString = _Alloca(64)) == 0) { _DisposeMenu(menuId); _Error(182); // "Insufficient memory" } intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 0), shortcutString); _PutStr("\nShortcut string = "); _PutStr(shortcutString); _PutStr("\nInternal key code ="); putLong(intKeyCode); intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 1), shortcutString); _PutStr("\nShortcut string = "); _PutStr(shortcutString); _PutStr("\nInternal key code ="); putLong(intKeyCode); intKeyCode = _GetItemCmdKey(menuId, _GetItemId(menuId, 2), shortcutString); _PutStr("\nShortcut string = "); _PutStr(shortcutString); _PutStr("\nInternal key code ="); putLong(intKeyCode); _Execute("WAIT"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetItemCmdKeyEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ;Setting environment for using Microsoft Visual C++ tools. TITEMID _GetItemId(MENUID menuid, long index) This example creates a menu with three items. It uses _GetItemId() to get the ITEMID of each menu item. After removing one item from the menu, we see that the ITEMID is not always equal to the item index. #include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetItemIdEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _PutStr("\nitemid for index 0 ="); putLong(_GetItemId(menuId, 0)); _PutStr("\nitemid for index 1 ="); putLong(_GetItemId(menuId, 1)); _PutStr("\nitemid for index 2 ="); putLong(_GetItemId(menuId, 2)); _Execute("WAIT"); _DisposeItem(menuId, _GetItemId(menuId, 1)); _PutStr("\nitemid for index 0 ="); putLong(_GetItemId(menuId, 0)); _PutStr("\nitemid for index 1 ="); putLong(_GetItemId(menuId, 1)); _Execute("WAIT"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetItemIdEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00219. example.c link.exe @d:\temp\nmb00219. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _GetItemText(MENUID menuid, ITEMID itemid, char FAR *text) This example sets up a menu with three items and then retreives the text of each item with _GetItemText().#include void FAR GetItemTextEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; char FAR *itemText; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); if ((itemText = _Alloca(80)) == 0) { _Error(182); // "Insufficient memory" } _GetItemText(menuId, _GetItemId(menuId, 0), itemText); _PutStr("\nItem text of 1st item = "); _PutStr(itemText); _GetItemText(menuId, _GetItemId(menuId, 1), itemText); _PutStr("\nItem text of 2nd item = "); _PutStr(itemText); _GetItemText(menuId, _GetItemId(menuId, 2), itemText); _PutStr("\nItem text of 3rd item = "); _PutStr(itemText); _Execute("WAIT"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetItemTextEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00228. example.c link.exe @d:\temp\nmb00228. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDITEMID _GetNewItemId(MENUID menuid) This example builds a menu with three items. Before each item is added to the menu, a unique ITEMID is generated by calling _GetNewItemId().#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00107. example.c link.exe @d:\temp\nmb00107. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDMENUID _GetNewMenuId(void) This example builds a menu with three items. Before a menu can be create using _NewMenu(), a unique MENUID must be generated by calling _GetNewMenuId().#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00262. example.c link.exe @d:\temp\nmb00262. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED"int _GetNextEvent(EventRec FAR *event) This example is a loop consisting of a call to _GetNextEvent() followed by a call to _DefaultProcess(). All events received get their default processing. f#include void FAR Example(ParamBlk FAR *parm) { EventRec ev; int i; for (i = 0; i < 16; i++) { _GetNextEvent(&ev); _DefaultProcess(&ev); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00149. example.c link.exe @d:\temp\nmb00149. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _GlobalToLocal(Point FAR *pt, WHANDLE wh) This example waits for a left mouse button click and then using _FindWindow() gets the window handle for the mouse position. _GlobalToLocal() takes both the window handle and the absolute mouse position as parameters to convert the mouse position to a position relative to the window. #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MyFindWindowEx(ParamBlk FAR *parm) { WHANDLE wh; Point mousePos; int where; // // Get mouse position when left button goes down // while (_InKey(0, MOUSEACTIVE | HIDECURSOR) != 151); while (!_MousePos(&mousePos)); switch (where = _FindWindow(&wh, mousePos)) { case inBorder: _PutStr("\nMouse down inBorder"); break; case inHelp: _PutStr("\nMouse down inHelp"); break; case inContent: _PutStr("\nMouse down inContent"); break; case inDrag: _PutStr("\nMouse down inDrag"); break; case inGrow: _PutStr("\nMouse down inGrow"); break; case inGoAway: _PutStr("\nMouse down inGoAway"); break; case inZoom: _PutStr("\nMouse down inZoom"); break; case inVUpArrow: _PutStr("\nMouse down inVUpArrow"); break; case inVDownArrow: _PutStr("\nMouse down inVDownArrow"); break; case inVPageUp: _PutStr("\nMouse down inVPageUp"); break; case inVPageDown: _PutStr("\nMouse down inVPageDown"); break; case inVThumb: _PutStr("\nMouse down inVThumb"); break; case inHUpArrow: _PutStr("\nMouse down inHUpArrow"); break; case inHDownArrow: _PutStr("\nMouse down inHDownArrow"); break; case inHPageUp: _PutStr("\nMouse down inHPageUp"); break; case inHPageDown: _PutStr("\nMouse down inHPageDown"); break; case inHThumb: _PutStr("\nMouse down inHThumb"); break; case inMenuBar: _PutStr("\nMouse down inMenuBar"); break; default: _PutStr("\nMouse down someplace else"); break; } _GlobalToLocal(&mousePos, wh); _PutStr("\nPosition relative to window:"); putLong(mousePos.v, 5); _PutChr(' '); putLong(mousePos.h, 5); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) MyFindWindowEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00249. example.c link.exe @d:\temp\nmb00249. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _GlobalToLocalP(Point FAR *pt, WHANDLE wh) This example waits for a left mouse button click and then using _FindWindowP() gets the window handle for the mouse position. _GlobalToLocalP() takes both the window handle and the absolute mouse position as parameters to convert the mouse position to a position relative to the window. #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MyFindWindowEx(ParamBlk FAR *parm) { WHANDLE wh; Point mousePos; int where; // // Get mouse position when left button goes down // while (_InKey(0, MOUSEACTIVE | HIDECURSOR) != 151); while (!_MousePosP(&mousePos)); switch (where = _FindWindowP(&wh, mousePos)) { case inBorder: _PutStr("\nMouse down inBorder"); break; case inHelp: _PutStr("\nMouse down inHelp"); break; case inContent: _PutStr("\nMouse down inContent"); break; case inDrag: _PutStr("\nMouse down inDrag"); break; case inGrow: _PutStr("\nMouse down inGrow"); break; case inGoAway: _PutStr("\nMouse down inGoAway"); break; case inZoom: _PutStr("\nMouse down inZoom"); break; case inVUpArrow: _PutStr("\nMouse down inVUpArrow"); break; case inVDownArrow: _PutStr("\nMouse down inVDownArrow"); break; case inVPageUp: _PutStr("\nMouse down inVPageUp"); break; case inVPageDown: _PutStr("\nMouse down inVPageDown"); break; case inVThumb: _PutStr("\nMouse down inVThumb"); break; case inHUpArrow: _PutStr("\nMouse down inHUpArrow"); break; case inHDownArrow: _PutStr("\nMouse down inHDownArrow"); break; case inHPageUp: _PutStr("\nMouse down inHPageUp"); break; case inHPageDown: _PutStr("\nMouse down inHPageDown"); break; case inHThumb: _PutStr("\nMouse down inHThumb"); break; case inMenuBar: _PutStr("\nMouse down inMenuBar"); break; default: _PutStr("\nMouse down someplace else"); break; } _GlobalToLocalP(&mousePos, wh); _PutStr("\nPosition relative to window:"); putLong(mousePos.v, 5); _PutChr(' '); putLong(mousePos.h, 5); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)MyFindWindowEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00268. example.c link.exe @d:\temp\nmb00268. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid FAR * _HandToPtr(MHANDLE hand) This example displays its character parameter on the screen. It uses _HandToPtr() to dereference the memory handle of the API parameter to a C pointer.m#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { NullTerminate(&parm->p[0].val); _HLock(parm->p[0].val.ev_handle); _PutStr(_HandToPtr(parm->p[0].val.ev_handle)); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"HANDTOPTR", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; \SET LIBRARY TO example = HANDTOPTR("Hello, world.") && displays "Hello, world" on screen Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00093. example.c link.exe @d:\temp\nmb00093. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDAvoid _HLock(MHANDLE hand) This example displays its character parameter on the screen. It uses _HandToPtr() to dereference the memory handle of the API parameter to a C pointer. Because during the call to _PutStr() FoxPro may "decided" to reorganize memory, to insure proper execution we should call _HLock() on the memory handle. We are careful to _HUnLock() after we are done, because the performance of FoxPro can be adversely affected by locked memory handles. c#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { NullTerminate(&parm->p[0].val); _HLock(parm->p[0].val.ev_handle); _PutStr(_HandToPtr(parm->p[0].val.ev_handle)); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"HLOCK", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; ZSET LIBRARY TO example = HLOCK("Hello, world.") && displays "Hello, world" on screen Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00263. example.c link.exe @d:\temp\nmb00263. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _HUnLock(MHANDLE hand) This example uses _RetDateStr() to return a FoxPro date type assuming that the character parameter is a proper date. We are careful to _HUnLock() memory handles when they no longer need to be locked, because the performance of FoxPro can be adversely affected by locked memory handles. L#include void FAR dates(ParamBlk FAR *parm) { MHANDLE mh; char FAR *instring; if ((mh = _AllocHand(parm->p[0].val.ev_length + 1)) == 0) { _Error(182); // "Insufficient memory" } _HLock(mh); instring = _HandToPtr(mh); _MemMove(instring,_HandToPtr(parm->p[0].val.ev_handle),parm->p[0].val.ev_length); instring[parm->p[0].val.ev_length] = '\0'; _RetDateStr(instring); _HUnLock(mh); } FoxInfo myFoxInfo[] = { {"DATES", (FPFI) dates, 1, "C"} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; ISET LIBRARY TO example ? DATES("2/14/93") && returns date {02/14/93} Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00076. example.c link.exe @d:\temp\nmb00076. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _InKey(int timeout, int flag) This example shows the API function being called from FoxPro with two _InKey() flags being logically "orred.">#include void FAR Example(ParamBlk FAR *parm) { _RetInt(_InKey((int) parm->p[0].val.ev_long, (int) parm->p[1].val.ev_long), 10); } FoxInfo myFoxInfo[] = { {"XINKEY", (FPFI) Example, 2, "I,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example #define SHOWCURSOR 1 #define HIDECURSOR 2 #define MOUSEACTIVE 4 = XINKEY(0, SHOWCURSOR + MOUSEACTIVE) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00274. example.c link.exe @d:\temp\nmb00274. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _Load(Locator FAR *loc, Value FAR *val) This example converts to upper case a string argument passed by reference.t#include void FAR Upper(ParamBlk FAR *parm) { char FAR *pString; Value val; unsigned int i; // // _Load() and _Store are the functions of interest for pass-by-reference. // _Load(&parm->p[0].loc, &val); // // FoxPro doesn't check the type of pass-by-reference arguments, so we do. // if (val.ev_type != 'C') { _Error(9); // "Data type mismatch" } pString = _HandToPtr(val.ev_handle); for (i = 0; i < val.ev_length; i++) { if ('a' <= *pString && *pString <= 'z') { *pString += ('A' - 'a'); } pString++; } _Store(&parm->p[0].loc, &val); // // We need to free the handle that we created with _LOAD() // _FreeHand(val.ev_handle); } FoxInfo myFoxInfo[] = { {"XUPPER", (FPFI) Upper, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; :SET LIBRARY TO example x = "abc" = XUPPER(@x) ? x Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00237. example.c link.exe @d:\temp\nmb00237. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDcint _MemAvail(unsigned int size) This example builds a linked list of 1K memory allocations exhausting available memory. It frees allocations (of course) and returns the number of allocations made. _MemAvail() is used to terminate the first while-loop.D#include #define ALLOCSIZE 1024 void FAR Example(ParamBlk FAR *parm) { int nHandles = 0; MHANDLE head = 0, mh; while (_MemAvail(ALLOCSIZE)) { mh = _AllocHand(ALLOCSIZE); *((MHANDLE *) _HandToPtr(mh)) = head; head = mh; nHandles++; } _RetInt(nHandles, 10); while (head != 0) { mh = *((MHANDLE *) _HandToPtr(head)); _FreeHand(head); head = mh; } } FoxInfo myFoxInfo[] = { {"MEMAVAIL", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; QSET LIBRARY TO example ? MEMAVAIL() && displays approx. memory available in K Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00264. example.c link.exe @d:\temp\nmb00264. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _MemCmp(void FAR *ptr1, void FAR *ptr2, unsigned int length) This example uses _MemCmp() to compare two character parameters up to length of the shorter.#include #ifndef min #define min(a, b) ((a) < (b) ? (a) : (b)) #endif void FAR Example(ParamBlk FAR *parm) { int LenToCmp, RetValue; LenToCmp = min(parm->p[0].val.ev_length, parm->p[1].val.ev_length); _HLock(parm->p[0].val.ev_handle); _HLock(parm->p[1].val.ev_handle); RetValue = _MemCmp(_HandToPtr(parm->p[0].val.ev_handle), _HandToPtr(parm->p[1].val.ev_handle), LenToCmp); _RetInt(RetValue, 10); // does return control here _HUnLock(parm->p[0].val.ev_handle); _HUnLock(parm->p[1].val.ev_handle); } FoxInfo myFoxInfo[] = { {"MEMCMP", (FPFI) Example, 2, "C,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ? MEMCMP("Hello, world.", "Hello, world.") && returns 0 ? MEMCMP("Hello, world.", "Hello, wurld.") && returns non-0 Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00151. example.c link.exe @d:\temp\nmb00151. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _MemFill(void FAR *ptr, int character, unsigned int length) This example uses _MemFill() to duplicate the functionality of the FoxPro function REPLICATE().#include void FAR Example(ParamBlk FAR *parm) { char FAR *rep; char c = *(char *) _HandToPtr(parm->p[0].val.ev_handle); rep = _Alloca((int) parm->p[1].val.ev_long + 1); _MemFill(rep, c, (int) parm->p[1].val.ev_long); rep[parm->p[1].val.ev_long] = '\0'; _RetChar(rep); } FoxInfo myFoxInfo[] = { {"XREPLICATE", (FPFI) Example, 2, "C,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; BSET LIBRARY TO example x = xREPLICATE("x", 120) ? x ? LEN(x) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00177. example.c link.exe @d:\temp\nmb00177. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED"void _MemMove(void FAR *dest, void FAR *src, unsigned int length) This example uses _MemMove() to implement a substring function. From FoxPro MEMMOVE(s, n1, n2) extracts the substring of s from position n1 to position n2.Y#include void FAR Example(ParamBlk FAR *parm) { int SubstrLen; MHANDLE bufferHandle; char FAR *FirstDest; SubstrLen = parm->p[2].val.ev_long - parm->p[1].val.ev_long + 1; if ((bufferHandle = _AllocHand(SubstrLen + 1)) == 0) { _Error(182); // "Insufficient memory" } _HLock(bufferHandle); _HLock(parm->p[0].val.ev_handle); FirstDest = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle) + parm->p[1].val.ev_long - 1; _MemMove(_HandToPtr(bufferHandle), FirstDest, SubstrLen); ((char FAR *) _HandToPtr(bufferHandle))[SubstrLen] = '\0'; _RetChar(_HandToPtr(bufferHandle)); _HUnLock(bufferHandle); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"MEMMOVE", (FPFI) Example, 3, "C,I,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; NSET LIBRARY TO example ? MEMMOVE("Hello, world.", 8, 10) && returns "wor" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00204. example.c link.exe @d:\temp\nmb00204. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDQFCHAN _MemoChan(int workarea) This example retrieves the contents of a memo field. _MemoChan(-1) returns a FCHAN to the memo file for the current work area. This FCHAN is used as an argument to the low level file I/O API callbacks.r#include void FAR FindMemoEx(ParamBlk FAR *parm) { Locator FAR *memoFldLoc; FCHAN fchMemo; char FAR *memoContents; int memoLen; long loc; if ((fchMemo = _MemoChan(-1)) == -1) { _UserError("_MemoChan() failed"); } memoFldLoc = &parm->p[0].loc; if ((loc = _FindMemo(memoFldLoc)) < 0) { _UserError("_FindMemo() failed"); } if ((memoLen = _MemoSize(memoFldLoc)) < 0) { _UserError("_MemoSize() failed"); } if ((memoContents = _Alloca(memoLen + 1)) == 0) { _Error(182); // "Insufficient memory" } _FSeek(fchMemo, loc, FS_FROMBOF); _FRead(fchMemo, memoContents, memoLen); memoContents[memoLen] = '\0'; _RetChar(memoContents); } FoxInfo myFoxInfo[] = { {"GETMEMO", (FPFI) FindMemoEx, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example CREATE TABLE WMemo (MemoField M) APPEND BLANK REPLACE MemoField WITH "Hello, World." ? GETMEMO(@MemoField) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00251. example.c link.exe @d:\temp\nmb00251. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDClong _MemoSize(Locator FAR *fld) This example retrieves the contents of a memo field. We call _MemoSize() to determine how much memory should be allocated for a buffer and how many bytes should be read from the memo file.r#include void FAR FindMemoEx(ParamBlk FAR *parm) { Locator FAR *memoFldLoc; FCHAN fchMemo; char FAR *memoContents; int memoLen; long loc; if ((fchMemo = _MemoChan(-1)) == -1) { _UserError("_MemoChan() failed"); } memoFldLoc = &parm->p[0].loc; if ((loc = _FindMemo(memoFldLoc)) < 0) { _UserError("_FindMemo() failed"); } if ((memoLen = _MemoSize(memoFldLoc)) < 0) { _UserError("_MemoSize() failed"); } if ((memoContents = _Alloca(memoLen + 1)) == 0) { _Error(182); // "Insufficient memory" } _FSeek(fchMemo, loc, FS_FROMBOF); _FRead(fchMemo, memoContents, memoLen); memoContents[memoLen] = '\0'; _RetChar(memoContents); } FoxInfo myFoxInfo[] = { {"GETMEMO", (FPFI) FindMemoEx, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example CREATE TABLE WMemo (MemoField M) APPEND BLANK REPLACE MemoField WITH "Hello, World." ? GETMEMO(@MemoField) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00266. example.c link.exe @d:\temp\nmb00266. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED(MENUID _MenuId(long literal) This example adds a pad to the system menu. It then attaches a popup menu with two items to this pad. _MenuId() is used to obtain the MENUID of the system menu.#include MENUID SysMenuId; MENUID PopupId; ITEMID PadId; void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); return 0; } void FAR StartUp() { ITEMID Bar1Id; ITEMID Bar2Id; int Error; // // Add new pad to SYSMENU. // SysMenuId = _MenuId(_SYSMENU); PadId = _GetNewItemId(SysMenuId); if (_NewItem(SysMenuId, PadId, _LASTITEM, "\\ void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00039. example.c link.exe @d:\temp\nmb00039. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _MousePos(Point FAR *pt) This example displays the current mouse position until it detects a left mouse button click.5#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MousePosEx(ParamBlk FAR *parm) { Point mousePos; while (!_MousePos(&mousePos)) { _PutStr("\nvertical ="); putLong(mousePos.v, 5); _PutStr("; horizontal ="); putLong(mousePos.h, 5); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) MousePosEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00087. example.c link.exe @d:\temp\nmb00087. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _MousePosP(Point FAR *pt) This example displays the current mouse position until it detects a left mouse button click.: #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR MousePosPEx(ParamBlk FAR *parm) { Point mousePos; while (!_MousePosP(&mousePos)) { _PutStr("\nvertical ="); putLong(mousePos.v, 5); _PutStr("; horizontal ="); putLong(mousePos.h, 5); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) MousePosPEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00140. example.c link.exe @d:\temp\nmb00140. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED0NTI _NameTableIndex(char FAR *name) This example releases a memory variable whose name is given as a character argument. Note that _NameTableIndex() this finds the variable name after it has been released.o#include void FAR ReleaseEx(ParamBlk FAR *parm) { NTI nti; char FAR *name; int exitCode; Locator loc; // // Null terminate character string, name of variable // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); name[parm->p[0].val.ev_length] = '\0'; if ((nti = _NameTableIndex(name)) == -1) { _HUnLock(parm->p[0].val.ev_handle); _UserError("Cannot find variable in name table."); } _HUnLock(parm->p[0].val.ev_handle); if (_FindVar(nti, -1, &loc)) { _PutStr("\nVariable exists prior to _Release()."); } if ((exitCode =_Release(nti)) < 0) { _Error(-exitCode); } _HLock(parm->p[0].val.ev_handle); name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); name[parm->p[0].val.ev_length] = '\0'; if ((nti = _NameTableIndex(name)) != -1) { _PutStr("\n_NameTableIndex() still finds variable after it is released."); } _HUnLock(parm->p[0].val.ev_handle); if (!_FindVar(nti, -1, &loc)) { _PutStr("\nVariable does not exist after _Release()."); } } FoxInfo myFoxInfo[] = { {"XRELEASE", (FPFI) ReleaseEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 7SET LIBRARY TO example x = 123 = XRELEASE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00193. example.c link.exe @d:\temp\nmb00193. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _NewItem(MENUID menuid, ITEMID itemid, ITEMID beforeid, char FAR *prompt) This example builds a menu with three items. _NewItem() is used to add each item to the menu.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -1, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00243. example.c link.exe @d:\temp\nmb00243. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _NewMenu(int mtype, MENUID menuid) This example creates a popup menu. _NewMenu() is used to create the menu specifying that we desire a popup type menu.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -1, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00261. example.c link.exe @d:\temp\nmb00261. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _NewVar(char FAR *name, Locator FAR *loc, int flag) This example uses _NewVar() to create three variables.#include void FAR NewVarEx(ParamBlk FAR *parm) { char FAR *varName; Locator loc; int flag; int retValue; // // Null terminate character string // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); varName = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); varName[parm->p[0].val.ev_length] = '\0'; loc.l_subs = (int) parm->p[1].val.ev_long; loc.l_sub1 = (int) parm->p[2].val.ev_long; loc.l_sub2 = (int) parm->p[3].val.ev_long; flag = parm->p[4].val.ev_long; if ((retValue = _NewVar(varName, &loc, flag)) < 0) { _Error(-retValue); // _NewVar() returns negative FoxPro error number } _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"XNEWVAR", (FPFI) NewVarEx, 5, "C,I,I,I,I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; :SET LIBRARY TO example * * As defined in "pro_ext.h" * #define NV_PUBLIC 0 #define NV_PRIVATE 1 = xNewVar('var', 0, 0, 0, NV_PUBLIC) DISPLAY MEMORY LIKE var = xNewVar('onedim', 1, 5, 0, NV_PUBLIC) DISPLAY MEMORY LIKE onedim = xNewVar('twodim', 2, 5, 6, NV_PUBLIC) DISPLAY MEMORY LIKE twodim Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00171. example.c link.exe @d:\temp\nmb00171. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDPvoid _OnSelection(MENUID menuid, ITEMID itemid, FPFI routine) This example creates a menu with three items. _OnSelection() is called with a ITEMID parameter of -1 indicating that the function onSelection() is to be called when any item from this menu is selected.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); _DisposeMenu(menuId); return 0; } void FAR activateMenu(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _OnSelection(menuId, -1, onSelection); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) activateMenu, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00181. example.c link.exe @d:\temp\nmb00181. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _PutChr(int char) This example uses _PutChr() to write all 8-bit characters to the screen.7#include void FAR Example(ParamBlk FAR *parm) { int ch; for (ch = 0; ch < 256; ch++) { _PutChr(ch); } } FoxInfo myFoxInfo[] = { {"PUTCHR", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00282. example.c link.exe @d:\temp\nmb00282. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _PutStr(char FAR *str) This example uses _PutStr() to display its character type parameter in upper case on the screen.^#include "pro_ext.h" void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { char FAR *pString; unsigned int i; NullTerminate(&parm->p[0].val); pString = _HandToPtr(parm->p[0].val.ev_handle); for (i = 0; i < parm->p[0].val.ev_length; i++) { if ('a' <= *pString && *pString <= 'z') { *pString += ('A' - 'a'); } pString++; } _HLock(parm->p[0].val.ev_handle); _PutStr(_HandToPtr(parm->p[0].val.ev_handle)); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"XUPPER", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; PSET LIBRARY TO example = XUPPER("upper") && displays "UPPER" on the screen Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00165. example.c link.exe @d:\temp\nmb00165. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _PutValue(Value FAR *val) This example uses _PutValue() to display its character type parameter in upper case on the screen.#include "pro_ext.h" void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { char FAR *pString; unsigned int i; NullTerminate(&parm->p[0].val); pString = _HandToPtr(parm->p[0].val.ev_handle); for (i = 0; i < parm->p[0].val.ev_length; i++) { if ('a' <= *pString && *pString <= 'z') { *pString += ('A' - 'a'); } pString++; } _PutValue(&parm->p[0].val); } FoxInfo myFoxInfo[] = { {"XUPPER", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; JSET LIBRARY TO example = XUPPER("upper") && displays "UPPER" on screen Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00293. example.c link.exe @d:\temp\nmb00293. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _Release(NTI n) This example releases a memory variable whose name is given as a character argument. _NameTableIndex() is used to find the NTI of the variable.o#include void FAR ReleaseEx(ParamBlk FAR *parm) { NTI nti; char FAR *name; int exitCode; Locator loc; // // Null terminate character string, name of variable // if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); name[parm->p[0].val.ev_length] = '\0'; if ((nti = _NameTableIndex(name)) == -1) { _HUnLock(parm->p[0].val.ev_handle); _UserError("Cannot find variable in name table."); } _HUnLock(parm->p[0].val.ev_handle); if (_FindVar(nti, -1, &loc)) { _PutStr("\nVariable exists prior to _Release()."); } if ((exitCode =_Release(nti)) < 0) { _Error(-exitCode); } _HLock(parm->p[0].val.ev_handle); name = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); name[parm->p[0].val.ev_length] = '\0'; if ((nti = _NameTableIndex(name)) != -1) { _PutStr("\n_NameTableIndex() still finds variable after it is released."); } _HUnLock(parm->p[0].val.ev_handle); if (!_FindVar(nti, -1, &loc)) { _PutStr("\nVariable does not exist after _Release()."); } } FoxInfo myFoxInfo[] = { {"XRELEASE", (FPFI) ReleaseEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 3SET LIBRARY TO example x = 123 = XRELEASE("x") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00141. example.c link.exe @d:\temp\nmb00141. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _RetChar(char FAR *string) #include void FAR chars(ParamBlk FAR *parm) { char message[] = "Hello, world"; _RetChar(message); } FoxInfo myFoxInfo[] = { {"CHARS", (FPFI) chars, 0, ""} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00286. example.c link.exe @d:\temp\nmb00286. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _RetFloat(double flt, int width, int dec) This example use _RetFloat() to return the floating point representation of a FoxPro date parameter. #include void FAR Example(ParamBlk FAR *parm) { _RetFloat(parm->p[0].val.ev_real, 20, 4); } FoxInfo myFoxInfo[] = { {"RETFLOAT", (FPFI) Example, 1, "D"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; kSET LIBRARY TO example ? RETFLOAT({2/14/93}) && returns floating point representation of date {2/14/93} Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00215. example.c link.exe @d:\temp\nmb00215. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _RetInt(long ival, int width) This example performs some operations on the DBF in the current work area. It returns the value returned by _RecCount() using _RetInt().[#include #define nl _PutChr('\n') long FAR CTest() { long rc,rec; int workarea = -1; int flag = 0; int rn; rc = _DBRewind(workarea); _PutStr("top"); nl; rc = _DBSkip(workarea, 5); _PutStr("skipped 5"); nl; rc = _DBAppend(workarea,flag); _PutStr("Appending"); nl; rc = _DBRewind(workarea); _PutStr("top"); nl; rn = _DBRecCount(workarea); _RetInt(rn, 10); rec = rn; return rn; } FoxInfo myFoxInfo[] ={ {"CTEST", (FPFI) CTest,0 , ""}, }; FoxTable _FoxTable = { (FoxTable FAR *)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00064. example.c link.exe @d:\temp\nmb00064. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _RetLogical(int flag) This example is coin flip. It returns .T. or .F. based on library function rand(). #include void FAR Example(ParamBlk FAR *parm) { _RetLogical(rand() % 2); } FoxInfo myFoxInfo[] = { {"RETLOGICAL", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; OSET LIBRARY TO example ? RETLOGICAL() && returns .T. or .F. pseudo-randomly Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00273. example.c link.exe @d:\temp\nmb00273. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _RetVal(Value FAR *val) This example uses _RetVal() to return its character type parameter converted to upper case.#include "pro_ext.h" void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { char FAR *pString; unsigned int i; NullTerminate(&parm->p[0].val); pString = _HandToPtr(parm->p[0].val.ev_handle); for (i = 0; i < parm->p[0].val.ev_length; i++) { if ('a' <= *pString && *pString <= 'z') { *pString += ('A' - 'a'); } pString++; } _RetVal(&parm->p[0].val); } FoxInfo myFoxInfo[] = { {"XUPPER", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; ASET LIBRARY TO example ? XUPPER("upper") && returns "UPPER" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00291. example.c link.exe @d:\temp\nmb00291. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _Set MenuColor(MENUID menuid, int scheme) This example creates a menu with three items in a color scheme specified by the calling parameter.#include void FAR SetMenuColorEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); _SetMenuColor(menuId, (int) parm->p[0].val.ev_long); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"MENUCOLOR", (FPFI) SetMenuColorEx, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 8SET LIBRARY TO example = MENUCOLOR(1) = MENUCOLOR(6) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00185. example.c link.exe @d:\temp\nmb00185. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _SetHandSize(MHANDLE hand, unsigned int size) This example uses _HandToPtr() to dereference a pass-by-value parameter from FoxPro to a C pointer. u#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { NullTerminate(&parm->p[0].val); _HLock(parm->p[0].val.ev_handle); _PutStr(_HandToPtr(parm->p[0].val.ev_handle)); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"HANDTOPTR", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; [SET LIBRARY TO example = HANDTOPTR("Hello, world.") && displays "Hello, world" on screen Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00278. example.c link.exe @d:\temp\nmb00278. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _SetItemCmdKey(MENUID menuid, ITEMID itemid, int key, char FAR *text) This example sets up a menu with three items and assigns a keyboard short cut to each item.#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); _DisposeMenu(menuId); return 0; } void FAR SetItemCmdKeyEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); _SetItemCmdKey(menuId, itemId, altKey | 0x178, "Alt+1"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); _SetItemCmdKey(menuId, itemId, altKey | 0x179, "Alt+2"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); _SetItemCmdKey(menuId, itemId, altKey | 0x17a, "Alt+3"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _OnSelection(menuId, -1, onSelection); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) SetItemCmdKeyEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00230. example.c link.exe @d:\temp\nmb00230. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _SetItemColor(MENUID menuid, ITEMID itemid, int scheme) In this example each of the three items is display in a different color scheme. Real pretty?!@#include void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } void FAR GetNewItemId(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); _SetItemColor(menuId, itemId, ALERT_SCHEME); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); _SetItemColor(menuId, itemId, DIALOG_SCHEME); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); _SetItemColor(menuId, itemId, WINDOW_SCHEME); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _PutStr("\nmenuId ="); putLong(menuId); _PutStr("\nitemId ="); putLong(itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) GetNewItemId, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00265. example.c link.exe @d:\temp\nmb00265. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _SetItemSubMenu(MENUID menuid, ITEMID itemid, MENUID submenuid) This example adds a pad to the system menu. Using _SetItemSubMenu(), It then attaches a popup menu with two items to this pad.#include MENUID SysMenuId; MENUID PopupId; ITEMID PadId; void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); return 0; } void FAR StartUp() { ITEMID Bar1Id; ITEMID Bar2Id; int Error; // // Add new pad to SYSMENU. // SysMenuId = _MenuId(_SYSMENU); PadId = _GetNewItemId(SysMenuId); if (_NewItem(SysMenuId, PadId, _LASTITEM, "\\ void FAR SetItemTextEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _ActivateMenu(menuId); _Execute("WAIT WINDOW 'Original item text'"); _SetItemText(menuId, _GetItemId(menuId, 0), "This was the 1st item"); _SetItemText(menuId, _GetItemId(menuId, 1), "This was the 2nd item"); _SetItemText(menuId, _GetItemId(menuId, 2), "This was the 3rd item"); _Execute("WAIT WINDOW 'New item text'"); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) SetItemTextEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00289. example.c link.exe @d:\temp\nmb00289. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _SetMenuPoint(MENUID menuid, Point loc) A menu is created and then activated at three different positions specified by _SetMenuPoint().#include void FAR SetMenuPointEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 10; loc.h = 20; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); loc.v = 15; loc.h = 30; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); loc.v = 20; loc.h = 40; _SetMenuPoint(menuId, loc); _MenuInteract(&menuId, &itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) SetMenuPointEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00158. example.c link.exe @d:\temp\nmb00158. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _SetMenuPointP(MENUID menuid, Point loc) A menu is created and then activated at three different positions specified by _SetMenuPointP().#include void FAR SetMenuPointPEx(ParamBlk FAR *parm) { MENUID menuId; ITEMID itemId; Point loc; menuId = _GetNewMenuId(); _NewMenu(MPOPUP, menuId); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<1st item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<2nd item"); itemId = _GetNewItemId(menuId); _NewItem(menuId, itemId, -2, "\\<3rd item"); loc.v = 40; loc.h = 80; _SetMenuPointP(menuId, loc); _MenuInteract(&menuId, &itemId); loc.v = 80; loc.h = 160; _SetMenuPointP(menuId, loc); _MenuInteract(&menuId, &itemId); loc.v = 160; loc.h = 320; _SetMenuPointP(menuId, loc); _MenuInteract(&menuId, &itemId); _DisposeMenu(menuId); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)SetMenuPointPEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00298. example.c link.exe @d:\temp\nmb00298. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _Store(Locator FAR *loc, Value FAR *val) This example converts to upper case a string argument passed by reference.g#include void FAR Upper(ParamBlk FAR *parm) { char FAR *pString; Value val; unsigned int i; // // _Load() and _Store are the functions of interest for pass-by-reference. // _Load(&parm->p[0].loc, &val); // // FoxPro doesn't check the type of pass-by-reference arguments, so we do. // if (val.ev_type != 'C') { _Error(9); // "Data type mismatch" } pString = _HandToPtr(val.ev_handle); for (i = 0; i < val.ev_length; i++) { if ('a' <= *pString && *pString <= 'z') { *pString += ('A' - 'a'); } pString++; } _Store(&parm->p[0].loc, &val); // // We need to free the handle that we created with _LOAD() // _FreeHand(val.ev_handle); } FoxInfo myFoxInfo[] = { {"XUPPER", (FPFI) Upper, 1, "R"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 9SET LIBRARY TO example x = "abc" = XUPPER(@x) ? x Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00204. example.c link.exe @d:\temp\nmb00204. LINK : fatal error LNK1104: cannot open file ".\example.fll" BUILD SUCCEEDEDint _StrCmp(char FAR *string1, char FAR *string2) This example uses _StrCmp() to compare two FoxPro strings passed as parameters.g#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { int RetValue; NullTerminate(&parm->p[0].val); NullTerminate(&parm->p[1].val); _HLock(parm->p[0].val.ev_handle); _HLock(parm->p[1].val.ev_handle); RetValue = _StrCmp(_HandToPtr(parm->p[0].val.ev_handle), _HandToPtr(parm->p[1].val.ev_handle)); _RetInt(RetValue, 10); // does return control here _HUnLock(parm->p[0].val.ev_handle); _HUnLock(parm->p[1].val.ev_handle); } FoxInfo myFoxInfo[] = { {"STRCMP", (FPFI) Example, 2, "C,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example ? STRCMP("Hello, world.", "Hello, world.") && strings same; return 0 ? STRCMP("Hello, world.", "Hello, wurld.") && strings diff; return non-0 Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00289. example.c link.exe @d:\temp\nmb00289. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _StrCpy(char FAR *dest, char FAR *src) This example uses _StrCpy() to return a character type to FoxPro that is the concatenation of its two character type parameters. Notice that although the memory handle of the parameter's Value structure is used as working memory to perform the concatenation, changes to this memory allocation do not affect the pass-by-value FoxPro argument. #include void FAR Example(ParamBlk FAR *parm) { #define p0 (parm->p[0].val) #define p1 (parm->p[1].val) if (!_SetHandSize(p0.ev_handle, p0.ev_length + p1.ev_length+1)) _Error(182); // "Insufficient memory" _HLock(p0.ev_handle); _HLock(p1.ev_handle); _MemMove((char FAR *) _HandToPtr(p0.ev_handle) + p0.ev_length, _HandToPtr(p1.ev_handle),p1.ev_length); p0.ev_length+=p1.ev_length+1; ((char *)_HandToPtr(p0.ev_handle))[p0.ev_length-1] = '\0'; _RetChar(_HandToPtr(p0.ev_handle)); _HUnLock(p0.ev_handle); _HUnLock(p1.ev_handle); } FoxInfo myFoxInfo[] = { {"STRCPY", (FPFI) Example, 2, "C,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; PSET LIBRARY TO example ? STRCPY("Hello", " world") && returns "Hello world" Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00275. example.c link.exe @d:\temp\nmb00275. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _StrLen(char FAR *string) This example is similar to the FoxPro function LEN(), but can't handle strings with embedded '\0'. y#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) { _Error(182); // "Insufficient memory" } ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR Example(ParamBlk FAR *parm) { NullTerminate(&parm->p[0].val); _HLock(parm->p[0].val.ev_handle); _RetInt(_StrLen(_HandToPtr(parm->p[0].val.ev_handle)), 10); _HUnLock(parm->p[0].val.ev_handle); } FoxInfo myFoxInfo[] = { {"STRLEN", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; :SET LIBRARY TO example ? STRLEN("Hello") && returns 5 Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00282. example.c link.exe @d:\temp\nmb00282. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _UserError(char FAR *message) This example calls _UserError() demonstrating that execution does not return to the API routine after a call to _UserError().]#include void FAR UserErrorEx(ParamBlk FAR *parm) { _UserError("This is a _UserError() example."); _PutStr("This should never be displayed."); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) UserErrorEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00187. example.c link.exe @d:\temp\nmb00187. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WBottom(WHANDLE wh) This example displays the position of the topmost window.b#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTop(wh), 5); _PutStr("\nleft ="); putLong(_WLeft(wh), 5); _PutStr("\nbottom ="); putLong(_WBottom(wh), 5); _PutStr("\nright ="); putLong(_WRight(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00251. example.c link.exe @d:\temp\nmb00251. LINK : fatal error LNK1104: cannot open file ".\example.fll" BUILD SUCCEEDEDint _WBottomP(WHANDLE wh) This example displays the position of the topmost window.e#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTopP(wh), 5); _PutStr("\nleft ="); putLong(_WLeftP(wh), 5); _PutStr("\nbottom ="); putLong(_WBottomP(wh), 5); _PutStr("\nright ="); putLong(_WRightP(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00276. example.c link.exe @d:\temp\nmb00276. LINK : fatal error LNK1104: cannot open file ".\example.fll" BUILD SUCCEEDEDvoid _WClear(WHANDLE wh) This example creates a window and fills it with "X"s. When a key is pressed in response to WAIT, the window is cleared using _WClear().l#include void FAR WClearEx(ParamBlk FAR *parm) { WHANDLE wh; unsigned int row, col; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (row = 0; row < _WHeight(wh); row++) { for (col = 0; col < _WWidth(wh); col++) { _WPutChr(wh, 'X'); } _WPutChr(wh, '\n'); } _Execute("WAIT 'Press any key to clear window'"); _WClear(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WClearEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00186. example.c link.exe @d:\temp\nmb00186. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED%void _WClearRect(WHANDLE wh, Rect r) This example creates a window and fills it with "X"s. After a key press in reponse to WAIT, a rectangular region of the window is cleared using _WClearRect().#include void FAR WClearEx(ParamBlk FAR *parm) { WHANDLE wh; unsigned int row, col; Rect r; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (row = 0; row < _WHeight(wh); row++) { for (col = 0; col < _WWidth(wh); col++) { _WPutChr(wh, 'X'); } } _Execute("WAIT 'Press any key to clear window rectangle'"); r.top = 2; r.left = 2; r.bottom = 15; r.right = 65; _WClearRect(wh, r); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WClearEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00271. example.c link.exe @d:\temp\nmb00271. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED%void _WClearRectP(WHANDLE wh, Rect r) This example creates a window and fills it with "X"s. After a key press in reponse to WAIT, a rectangular region of the window is cleared using _WClearRect().#include void FAR WClearEx(ParamBlk FAR *parm) { WHANDLE wh; unsigned int row, col; Rect r; wh = _WOpen(2, 2, 20, 70, CLOSE, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); for (row = 0; row < _WHeight(wh); row++) { for (col = 0; col < _WWidth(wh); col++) { _WPutChr(wh, 'X'); } } _Execute("WAIT 'Press any key to clear window rectangle'"); r.top = 20; r.left = 20; r.bottom = 100; r.right = 300; _WClearRectP(wh, r); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)WClearEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00269. example.c link.exe @d:\temp\nmb00269. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WClose(WHANDLE wh) This example creates and displays a window. After a key is pressed in response to WAIT, the window is closed with _WClose().#include void FAR Ex(ParamBlk FAR *parm) { WHANDLE wh; wh = _WOpen(2, 2, 20, 70, 0, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); _Execute("WAIT 'Press any key to close window'"); _WClose(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Ex, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00215. example.c link.exe @d:\temp\nmb00215. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDWHANDLE _WFindTitle(TEXT *title) This example hides the window whose title is passed as an argument.#include void FAR WFindTitleEx(ParamBlk FAR *parm) { // // For readability--- // #define pTITLE ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pTITLE[parm->p[0].val.ev_length] = '\0'; wh = _WFindTitle(pTITLE); _HUnLock(parm->p[0].val.ev_handle); _WHide(wh); } FoxInfo myFoxInfo[] = { {"WHIDE", (FPFI) WFindTitleEx, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; OSET LIBRARY TO example CREATE TABLE X (X C(10)) BROWSE NOWAIT = WHIDE("X") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00187. example.c link.exe @d:\temp\nmb00187. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED&void _WFooter(WHANDLE wh, char FAR *footer) This example creates and displays a window with both a title and a footer. The title and footer text is retrieved using _WTitle() and _WFooter() and displayed.#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char FAR *buffer; wh = _WOpen(4, 4, 20, 70, CLOSE | WEVENT, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WSetTitle(wh, "This is a window title"); _WSetFooter(wh, "This is a window footer"); _WShow(wh); if ((buffer = _Alloca(128)) == 0) { _Error(182); // "Insufficient memory" } _WTitle(wh, buffer); _PutStr("\nThe window title is \""); _PutStr(buffer); _PutChr('"'); _WFooter(wh, buffer); _PutStr("\nThe window footer is \""); _PutStr(buffer); _PutChr('"'); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00220. example.c link.exe @d:\temp\nmb00220. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDEPoint _WGetCursor(WHANDLE wh) This example creates a window and puts a diagonal of "X"s in this window. It positions the cursor before writing each "X" using _WPosCursor() and gets that same position using _WGetCursor().-#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; Point putPos, getPos; wh = _WOpen(4, 4, 20, 70, 0, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (putPos.v = 2; putPos.v < 14; putPos.v++) { putPos.h = putPos.v; _WPosCursor(wh, putPos); getPos = _WGetCursor(wh); _WPutChr(wh, 'X'); _PutStr("\nCursor position:"); putLong(getPos.v, 5); putLong(getPos.h, 5); _Execute("WAIT"); } _WClose(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00138. example.c link.exe @d:\temp\nmb00138. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDWHANDLE _WGetPort(void) This example displays the window handle returned by _WGetPort() as the current output port is changed.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; WHANDLE oldPort; wh = _WOpen(2, 10, 23, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); _PutStr("\n1) _WGetPort() ="); putLong(_WGetPort(), 10); oldPort = _WSetPort(wh); _PutStr("\n2) _WSetPort(wh) ="); putLong(oldPort, 10); _PutStr("\n3) _WGetPort() ="); putLong(_WGetPort(), 10); oldPort = _WSetPort(oldPort); _PutStr("\n4) _WSetPort(oldPort) ="); putLong(oldPort, 10); _PutStr("\nShould be back where we started."); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00270. example.c link.exe @d:\temp\nmb00270. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WHeight(WHANDLE wh) This example displays the height and width of the topmost window.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\nheight ="); putLong(_WHeight(wh), 5); _PutStr("\nwidth ="); putLong(_WWidth(wh), 5); } FoxInfo myFoxInfo[] = { {"WDIMEN", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00274. example.c link.exe @d:\temp\nmb00274. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WHeightP(WHANDLE wh) This example displays the height and width in pixels of the topmost window.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\nheight ="); putLong(_WHeightP(wh), 5); _PutStr("\nwidth ="); putLong(_WWidthP(wh), 5); } FoxInfo myFoxInfo[] = { {"WDIMEN", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00276. example.c link.exe @d:\temp\nmb00276. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WHide(WHANDLE wh) This example hides the window whose title is passed as an argument.#include void FAR Example(ParamBlk FAR *parm) { // // For readability--- // #define pTITLE ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle)) WHANDLE wh; if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1)) { _Error(182); // "Insufficient memory" } _HLock(parm->p[0].val.ev_handle); pTITLE[parm->p[0].val.ev_length] = '\0'; wh = _WFindTitle(pTITLE); _HUnLock(parm->p[0].val.ev_handle); _WHide(wh); } FoxInfo myFoxInfo[] = { {"WHIDE", (FPFI) Example, 1, "C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; RSET LIBRARY TO example CREATE TABLE X (X C(10)) BROWSE NOWAIT = WHIDE("X") Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00299. example.c link.exe @d:\temp\nmb00299. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WLeft(WHANDLE wh) This example displays the position of the topmost window.b#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTop(wh), 5); _PutStr("\nleft ="); putLong(_WLeft(wh), 5); _PutStr("\nbottom ="); putLong(_WBottom(wh), 5); _PutStr("\nright ="); putLong(_WRight(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00144. example.c link.exe @d:\temp\nmb00144. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WLeftP(WHANDLE wh) This example displays the position of the topmost window.e#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTopP(wh), 5); _PutStr("\nleft ="); putLong(_WLeftP(wh), 5); _PutStr("\nbottom ="); putLong(_WBottomP(wh), 5); _PutStr("\nright ="); putLong(_WRightP(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00123. example.c link.exe @d:\temp\nmb00123. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WMove(WHANDLE wh, Point pt) This example moves the topmost window diagonally ten rows down and ten columns to the right.o#include void FAR WMoveEx(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); Point newPos; newPos.v = _WTop(wh) + 10; newPos.h = _WLeft(wh) + 10; _WMove(wh, newPos); } FoxInfo myFoxInfo[] = { {"WMOVE", (FPFI) WMoveEx, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00138. example.c link.exe @d:\temp\nmb00138. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WMoveP(WHANDLE wh, Point pt) This example moves the topmost window diagonally forty pixels down and forty pixels to the right.t#include void FAR WMovePEx(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); Point newPos; newPos.v = _WTopP(wh) + 40; newPos.h = _WLeftP(wh) + 40; _WMoveP(wh, newPos); } FoxInfo myFoxInfo[] = { {"WMOVEP", (FPFI)WMovePEx, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00258. example.c link.exe @d:\temp\nmb00258. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDgHWND _WhToHwnd(WHANDLE) This example creates a window and then obtains the Windows HWND for the window with the callback _WhToHwnd(). Then, to verify the value returned by _WhToHwnd(), the example uses the HWND as an argument to a Windows function.#include #include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR WhToHwndEx(ParamBlk FAR *parm) { RECT Rect; HWND hwnd; WHANDLE wh; wh = _WOpenP(10, 10, 120, 240, CLOSE, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); // // Get Windows window handle and use as a parameter to a Windows function // hwnd = _WhToHwnd(wh); GetWindowRect(hwnd, &Rect); // Windows function _PutStr("\ntop ="); putLong(Rect.top, 5); _PutStr("\nleft ="); putLong(Rect.left, 5); _PutStr("\nbottom ="); putLong(Rect.bottom, 5); _PutStr("\nright ="); putLong(Rect.right, 5); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)WhToHwndEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00108. example.c link.exe @d:\temp\nmb00108. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDWHANDLE _WOnTop(void) This example displays position information of the window on top.a#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTop(wh), 5); _PutStr("\nleft ="); putLong(_WLeft(wh), 5); _PutStr("\nbottom ="); putLong(_WBottom(wh), 5); _PutStr("\nright ="); putLong(_WRight(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00187. example.c link.exe @d:\temp\nmb00187. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDLWHANDLE _WOpen(int top, int left, int bottom, int right, int flag, int scheme_num, Scheme FAR *scheme, char FAR *bord) This example creates windows using a number of different color schemes and borders. In particular, note the custom color scheme and custom border. (User specified border is available in DOS only.)#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char customBorder[] = "ABCDEFGHabcdefgh"; Scheme customScheme = { (char) (BLACK_ON | WHITE), (char) (RED_ON | BLACK | BLINK), (char) (WHITE_ON | WHITE | BRIGHT), (char) (CYAN_ON | BLUE | BRIGHT), (char) (GREEN_ON | BROWN), (char) (BROWN_ON | BROWN | BRIGHT), (char) (MAGENTA_ON | MAGENTA | BRIGHT), (char) (RED_ON | MAGENTA | BRIGHT | BLINK), (char) (BROWN_ON | GREEN | BRIGHT), (char) (BLACK_ON | CYAN), (char) (BLUE_ON | CYAN), }; _Execute("WAIT 'Press any key to see a window in WINDOW_SCHEME" " with WO_DOUBLEBOX border'"); wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_DOUBLEBOX); _WShow(wh); _Execute("WAIT 'Press any key to see a window in ALERT_SCHEME" " with WO_SINGLEBOX border'"); _WClose(wh); wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, ALERT_SCHEME, (Scheme FAR *) 0, WO_SINGLEBOX); _WShow(wh); _Execute("WAIT 'Press any key to see a window in WINDOW_SCHEME" " with WO_PANELBORDER border'"); _WClose(wh); wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_PANELBORDER); _WShow(wh); _Execute("WAIT 'Press any key to see a window in a custom scheme" " with WO_SYSTEMBORDER border'"); _WClose(wh); wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, -1, (Scheme FAR *) customScheme, WO_PANELBORDER); _WShow(wh); _Execute("WAIT 'Press any key to see a window in WINDOW_SCHEME" " with a custom border (DOS only)'"); _WClose(wh); wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, customBorder); _WShow(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00277. example.c link.exe @d:\temp\nmb00277. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDEvoid _WPosCursor(WHANDLE wh, Point pt) This example creates a window and puts a diagonal of "X"s in this window. It positions the cursor before writing each "X" using _WPosCursor() and gets that same position using _WGetCursor()./#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; Point putPos, getPos; wh = _WOpen(4, 4, 20, 70, 0, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (putPos.v = 2; putPos.v < 14; putPos.v++) { putPos.h = putPos.v; _WPosCursor(wh, putPos); _WPutChr(wh, 'X'); getPos = _WGetCursor(wh); _PutStr("\nCursor position:"); putLong(getPos.v, 5); putLong(getPos.h, 5); _Execute("WAIT"); } _WClose(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00106. example.c link.exe @d:\temp\nmb00106. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDGvoid _WPosCursorP(WHANDLE wh, Point pt) This example creates a window and puts a diagonal of "X"s in this window. It positions the cursor before writing each "X" using _WPosCursorP() and gets that same position using _WGetCursorP().'#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; Point putPos, getPos; wh = _WOpen(4, 4, 20, 70, 0, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); for (putPos.v = 10; putPos.v < 100; putPos.v += 10) { putPos.h = putPos.v; _WPosCursorP(wh, putPos); _WPutChr(wh, 'X'); getPos = _WGetCursorP(wh); _PutStr("\nCursor position:"); putLong(getPos.v, 5); putLong(getPos.h, 5); _Execute("WAIT"); } _WClose(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00260. example.c link.exe @d:\temp\nmb00260. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WPutChr(WHANDLE wh, int char) This example uses _WPutChr() to display all 8-bit values to a window it creates.#include void FAR Example(ParamBlk FAR *parm) { int i; WHANDLE wh; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (i = 0; i < 256; i++) _WPutChr(wh, i); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00280. example.c link.exe @d:\temp\nmb00280. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WPutStr(WHANDLE wh, char FAR *str) This example uses _WPutStr() to display a string containing all 8-bit values (except '\0') to a window it creates.#include void FAR Example(ParamBlk FAR *parm) { int i; WHANDLE wh; char String[256]; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); for (i = 0; i < 255; i++) String[i] = i + 1; String[255] = '\0'; _WPutStr(wh, String); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00285. example.c link.exe @d:\temp\nmb00285. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WRight(WHANDLE wh) This example displays the position of the topmost window.b#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTop(wh), 5); _PutStr("\nleft ="); putLong(_WLeft(wh), 5); _PutStr("\nbottom ="); putLong(_WBottom(wh), 5); _PutStr("\nright ="); putLong(_WRight(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00220. example.c link.exe @d:\temp\nmb00220. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WRightP(WHANDLE wh) This example displays the position of the topmost window.e#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTopP(wh), 5); _PutStr("\nleft ="); putLong(_WLeftP(wh), 5); _PutStr("\nbottom ="); putLong(_WBottomP(wh), 5); _PutStr("\nright ="); putLong(_WRightP(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00040. example.c link.exe @d:\temp\nmb00040. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WScroll(WHANDLE wh, Rect r, int dv, int dh) This example opens a window and draws a rectangle of "X"s. This rectangle is also the scroll rectangle. First, it is scrolled up two positions and to the left two positions. Next, it scrolled down by four positions and to the right four positions.`#include void FAR WScrollEx(ParamBlk FAR *parm) { WHANDLE wh; Point pos; Rect rect; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); rect.top = 6; rect.left = 6; rect.bottom = 12; rect.right = 12; for (pos.v = rect.top; pos.v < rect.bottom; pos.v++) { for (pos.h = rect.left; pos.h < rect.right; pos.h++) { _WPosCursor(wh, pos); _WPutChr(wh, 'X'); } } _Execute("WAIT 'Press any key to _WScroll(wh, rect, -2, -2)'"); _WScroll(wh, rect, -2, -2); _Execute("WAIT 'Press any key to _WScroll(wh, rect, +4, +4)'"); _WScroll(wh, rect, +4, +4); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WScrollEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00175. example.c link.exe @d:\temp\nmb00175. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED5void _WScrollP(WHANDLE wh, Rect r, int dv, int dh) This example opens a window and draws a rectangle of "X"s. This rectangle is also the scroll rectangle. First, it is scrolled up and left. Next, it scrolled down and right.N#include void FAR WScrollEx(ParamBlk FAR *parm) { WHANDLE wh; Point pos; Rect rect; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); rect.top = 6; rect.left = 6; rect.bottom = 12; rect.right = 12; for (pos.v = rect.top; pos.v < rect.bottom; pos.v++) { for (pos.h = rect.left; pos.h < rect.right; pos.h++) { _WPosCursor(wh, pos); _WPutChr(wh, 'X'); } } _Execute("WAIT 'Press any key to _WScroll(wh, rect, -2, -2)'"); _WScroll(wh, rect, -2, -2); _Execute("WAIT 'Press any key to _WScroll(wh, rect, +4, +4)'"); _WScroll(wh, rect, +4, +4); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)WScrollEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00297. example.c link.exe @d:\temp\nmb00297. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSelect(WHANDLE wh) This example creates five overlapping windows. The windows are _WSelect()-ed starting with the first created.D#include void FAR WSelectEx(ParamBlk FAR *parm) { WHANDLE wh[5]; int i; for (i = 0; i < 5; i++) { wh[i] = _WOpen(4 + 2*i, 4 + 2*i, 12 + 2*i, 40 + 2*i, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh[i]); } for (i = 0; i < 5; i++) { _Execute("WAIT 'Press key to _WSelect() next window'"); _WSelect(wh[i]); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WSelectEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00236. example.c link.exe @d:\temp\nmb00236. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSendBehind(WHANDLE wh) This example creates five overlapping windows. _WSendBehind() is called on each window starting with the last created.O#include void FAR WSendBehindEx(ParamBlk FAR *parm) { WHANDLE wh[5]; int i; for (i = 0; i < 5; i++) { wh[i] = _WOpen(4 + 2*i, 4 + 2*i, 12 + 2*i, 40 + 2*i, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh[i]); } for (i = 4; i >= 0; i--) { _Execute("WAIT 'Press key to _WSendBehind() next window'"); _WSendBehind(wh[i]); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WSendBehindEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00219. example.c link.exe @d:\temp\nmb00219. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSetFooter(WHANDLE wh, char FAR *footer) This example creates a window and sets its title text with _WSetTitle() and its footer text with _WSetFooter().#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char FAR *buffer; wh = _WOpen(4, 4, 20, 70, CLOSE | WEVENT, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WSetTitle(wh, "This is a window title"); _WSetFooter(wh, "This is a window footer"); _WShow(wh); if ((buffer = _Alloca(128)) == 0) { _Error(182); // "Insufficient memory" } _WTitle(wh, buffer); _PutStr("\nThe window title is \""); _PutStr(buffer); _PutChr('"'); _WFooter(wh, buffer); _PutStr("\nThe window footer is \""); _PutStr(buffer); _PutChr('"'); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00107. example.c link.exe @d:\temp\nmb00107. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDWHANDLE _WSetPort(WHANDLE wh) This example creates a window and makes this the output port. It writes some text to this window before switching back to the original output port.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; WHANDLE oldPort; wh = _WOpen(2, 10, 23, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); _PutStr("\n1) _WGetPort() ="); putLong(_WGetPort(), 10); oldPort = _WSetPort(wh); _PutStr("\n2) _WSetPort(wh) ="); putLong(oldPort, 10); _PutStr("\n3) _WGetPort() ="); putLong(_WGetPort(), 10); oldPort = _WSetPort(oldPort); _PutStr("\n4) _WSetPort(oldPort) ="); putLong(oldPort, 10); _PutStr("\nShould be back where we started."); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00262. example.c link.exe @d:\temp\nmb00262. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSetTitle(WHANDLE wh, char FAR *title) This example creates a window and sets its title text with _WSetTitle() and its footer text with _WSetFooter().#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char FAR *buffer; wh = _WOpen(4, 4, 20, 70, CLOSE | WEVENT, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WSetTitle(wh, "This is a window title"); _WSetFooter(wh, "This is a window footer"); _WShow(wh); if ((buffer = _Alloca(128)) == 0) { _Error(182); // "Insufficient memory" } _WTitle(wh, buffer); _PutStr("\nThe window title is \""); _PutStr(buffer); _PutChr('"'); _WFooter(wh, buffer); _PutStr("\nThe window footer is \""); _PutStr(buffer); _PutChr('"'); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00149. example.c link.exe @d:\temp\nmb00149. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED$void _WShow(WHANDLE wh) This example contains two API routines. WOPEN() opens a window but does not call _WShow(), showing that the window is not displayed until _WShow() is called.#include void FAR WOpen(ParamBlk FAR *parm) { _RetInt(_WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER), 10); } void FAR WShow(ParamBlk FAR *parm) { _WShow(parm->p[0].val.ev_long); } FoxInfo myFoxInfo[] = { {"WOPEN", (FPFI) WOpen, 0, ""}, {"WSHOW", (FPFI) WShow, 1, "I"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; 6SET LIBRARY TO example wh = WOPEN() = WSHOW(wh) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00249. example.c link.exe @d:\temp\nmb00249. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSize(WHANDLE wh, Point pt) This example creates a window and grows its width first, then its height.#include void FAR WSizeEx(ParamBlk FAR *parm) { WHANDLE wh; Point dim; wh = _WOpen(2, 2, 10, 10, CLOSE | WEVENT, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); dim.v = 8; // // Grow in width // for (dim.h = 8; dim.h < 60; dim.h += 4) { _WSize(wh, dim); _Execute("WAIT"); } // // Grow in height // for (dim.v = 8; dim.v < 20; dim.v += 2) { _WSize(wh, dim); _Execute("WAIT"); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) WSizeEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00268. example.c link.exe @d:\temp\nmb00268. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WSizeP(WHANDLE wh, Point pt) This example creates a window and grows its width first, then its height.|#include void FAR WSizeEx(ParamBlk FAR *parm) { WHANDLE wh; Point dim; wh = _WOpenP(6, 6, 20, 20, CLOSE | WEVENT, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); dim.v = 14; // // Grow in width // for (dim.h = 14; dim.h < 480; dim.h += 40) { _WSizeP(wh, dim); _Execute("WAIT"); } // // Grow in height // for (dim.v = 14; dim.v < 240; dim.v += 40) { _WSizeP(wh, dim); _Execute("WAIT"); } } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)WSizeEx, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00093. example.c link.exe @d:\temp\nmb00093. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED&void _WTitle(WHANDLE wh, char FAR *title) This example creates and displays a window with both a title and a footer. The title and footer text is retrieved using _WTitle() and _WFooter() and displayed.#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; char FAR *buffer; wh = _WOpen(4, 4, 20, 70, CLOSE | WEVENT, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WSetTitle(wh, "This is a window title"); _WSetFooter(wh, "This is a window footer"); _WShow(wh); if ((buffer = _Alloca(128)) == 0) { _Error(182); // "Insufficient memory" } _WTitle(wh, buffer); _PutStr("\nThe window title is \""); _PutStr(buffer); _PutChr('"'); _WFooter(wh, buffer); _PutStr("\nThe window footer is \""); _PutStr(buffer); _PutChr('"'); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00263. example.c link.exe @d:\temp\nmb00263. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WTop(WHANDLE wh) This example displays the position of the topmost window.b#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTop(wh), 5); _PutStr("\nleft ="); putLong(_WLeft(wh), 5); _PutStr("\nbottom ="); putLong(_WBottom(wh), 5); _PutStr("\nright ="); putLong(_WRight(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00076. example.c link.exe @d:\temp\nmb00076. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WTopP(WHANDLE wh) This example displays the position of the topmost window.e#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\ntop ="); putLong(_WTopP(wh), 5); _PutStr("\nleft ="); putLong(_WLeftP(wh), 5); _PutStr("\nbottom ="); putLong(_WBottomP(wh), 5); _PutStr("\nright ="); putLong(_WRightP(wh), 5); } FoxInfo myFoxInfo[] = { {"WPOSITION", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00274. example.c link.exe @d:\temp\nmb00274. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WWidth(WHANDLE wh) This example displays the height and width of the topmost window.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\nheight ="); putLong(_WHeight(wh), 5); _PutStr("\nwidth ="); putLong(_WWidth(wh), 5); } FoxInfo myFoxInfo[] = { {"WDIMEN", (FPFI) Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00119. example.c link.exe @d:\temp\nmb00119. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDint _WWidthP(WHANDLE wh) This example displays the height and width in pixels of the topmost window.#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh = _WOnTop(); _PutStr("\nheight ="); putLong(_WHeightP(wh), 5); _PutStr("\nwidth ="); putLong(_WWidthP(wh), 5); } FoxInfo myFoxInfo[] = { {"WDIMEN", (FPFI)Example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00264. example.c link.exe @d:\temp\nmb00264. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDvoid _WZoom(WHANDLE wh, int newstate) This example creates and displays a window. It then calls _WZoom() for this window with each of its parameters, WZ_MINIMIZE, WZ_NORMAL, and WZ_MAXIMIZE.#include void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; wh = _WOpen(2, 2, 20, 70, WEVENT | CLOSE, WINDOW_SCHEME, (Scheme FAR *) 0, WO_SYSTEMBORDER); _WShow(wh); _Execute("WAIT 'Press any key to minimize window'"); _WZoom(wh, WZ_MINIMIZED); _Execute("WAIT 'Press any key to normalize window'"); _WZoom(wh, WZ_NORMAL); _Execute("WAIT 'Press any key to maximize window'"); _WZoom(wh, WZ_MAXIMIZED); _Execute("WAIT 'Press any key to normalize window'"); _WZoom(wh, WZ_NORMAL); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI) Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00274. example.c link.exe @d:\temp\nmb00274. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDGPoint _WGetCursorP(WHANDLE wh) This example creates a window and puts a diagonal of "X"s in this window. It positions the cursor before writing each "X" using _WPosCursorP() and gets that same position using _WGetCursorP().'#include void putLong(long n, int width) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = width; _PutValue(&val); } void FAR Example(ParamBlk FAR *parm) { WHANDLE wh; Point putPos, getPos; wh = _WOpen(4, 4, 20, 70, 0, WINDOW_SCHEME, 0, WO_SYSTEMBORDER); _WShow(wh); for (putPos.v = 10; putPos.v < 100; putPos.v += 10) { putPos.h = putPos.v; _WPosCursorP(wh, putPos); _WPutChr(wh, 'X'); getPos = _WGetCursorP(wh); _PutStr("\nCursor position:"); putLong(getPos.v, 5); putLong(getPos.h, 5); _Execute("WAIT"); } _WClose(wh); } FoxInfo myFoxInfo[] = { {"ONLOAD", (FPFI)Example, CALLONLOAD, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO exampleSetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00256. example.c link.exe @d:\temp\nmb00256. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDlint _DBAppendRecords(int workarea, int numrecs, char FAR *buffer) This example creates a test DBF with two fields. Two records are appended to this DBF by calling the API routine which in turn calls _DBAppendRecords(). Notice that the append buffer must include a delete byte for each record. A#include void NullTerminate(Value FAR *cVal) { if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) _Error(182); // "Insufficient memory" ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0'; } void FAR xDBAppendRecords(ParamBlk FAR *parm) { int workarea = parm->p[0].val.ev_long; int nRecs = parm->p[1].val.ev_long; char FAR *buffer; int retCode; _HLock(parm->p[2].val.ev_handle); buffer = _HandToPtr(parm->p[2].val.ev_handle); retCode = _DBAppendRecords(workarea, (unsigned short) nRecs, buffer); _HUnLock(parm->p[2].val.ev_handle); if (retCode < 0) _Error(-retCode); } FoxInfo myFoxInfo[] = { {"DBAPPRECS", (FPFI) xDBAppendRecords, 3, "I,I,C"}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; SET LIBRARY TO example CREATE TABLE Test (City C(20), State C(2)) APPBUFFER = " PERRYSBURG OH" && include delete byte = ASCII space APPBUFFER = APPBUFFER + " REDMOND WA" = DBAPPRECS(-1, 2, APPBUFFER) LIST USESetting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00283. example.c link.exe @d:\temp\nmb00283. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDB#include void FAR example(ParamBlk FAR *parm) { WHANDLE wh = _WMainWindow(); _WPutStr(wh, "\nThis is the outermost FoxPro window."); } FoxInfo myFoxInfo[] = { {"EXWMAIN", (FPFI)example, 0, ""}, }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; %SET LIBRARY TO example = EXWMAIN() Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00240. example.c link.exe @d:\temp\nmb00240. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDEDs#include MENUID SysMenuId, retMenuId; MENUID PopupId; ITEMID PadId; void putLong(long n) { Value val; val.ev_type = 'I'; val.ev_long = n; val.ev_width = 10; _PutValue(&val); } FAR onSelection(long menuId, long itemId) { _PutStr("\nitemId = "); putLong(itemId); return 0; } void FAR StartUp() { ITEMID Bar1Id; ITEMID Bar2Id; int Error; // // Add new pad to SYSMENU. // SysMenuId = _MenuId(_SYSMENU); PadId = _GetNewItemId(SysMenuId); if (_NewItem(SysMenuId, PadId, _LASTITEM, "\\ #include void FAR retcurr(ParamBlk FAR *parm) { CCY money; money.HighPart = (long) (parm->p[0].val.ev_real*10000 / pow(2,32)); money.LowPart = (unsigned long) ((parm->p[0].val.ev_real - (double) (money.HighPart * pow(2,32)/10000.0)) *10000); _RetCurrency(money,25); } FoxInfo myFoxInfo[] = { {"XNTOM", (FPFI) retcurr, 1, "N"} }; FoxTable _FoxTable = { (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo }; (SET LIBRARY TO example ? xntom(100.1) Setting environment for using Microsoft Visual C++ tools. cl.exe @d:\temp\nma00190. example.c link.exe @d:\temp\nmb00190. Creating library .\example.lib and object .\example.exp BUILD SUCCEEDED